summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-04-07 19:42:45 +0200
committerhut <hut@lavabit.com>2010-04-07 19:42:45 +0200
commitbe7c282c2d73472254946f5043bf835f6bbb038a (patch)
tree6862f682b6fdddd5b104e0b127735f56307cf1cb
parent7626fd1d08ccb597ef25eaebf37ffc7be33c6df2 (diff)
downloadranger-be7c282c2d73472254946f5043bf835f6bbb038a.tar.gz
gui.ui: improvements in handling of special keys
-rw-r--r--ranger/core/fm.py6
-rw-r--r--ranger/gui/ui.py22
2 files changed, 24 insertions, 4 deletions
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index a408139a..ae815fbf 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -19,7 +19,6 @@ The File Manager, putting the pieces together
 
 from time import time
 from collections import deque
-from curses import KEY_MOUSE, KEY_RESIZE
 import os
 import sys
 
@@ -105,6 +104,11 @@ class FM(Actions, SignalDispatcher):
 		self.input_blocked = sec != 0
 		self.input_blocked_until = time() + sec
 
+	def input_is_blocked(self):
+		if self.input_blocked and time() > self.input_blocked_until:
+			self.input_blocked = False
+		return self.input_blocked
+
 	def loop(self):
 		"""
 		The main loop consists of:
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index c1a4bb60..8d355665 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -127,6 +127,10 @@ class UI(DisplayableContainer):
 		if hasattr(self, 'hint'):
 			self.hint()
 
+		if key < 0:
+			self.env.keybuffer.clear()
+			return
+
 		self.env.key_append(key)
 
 		if DisplayableContainer.press(self, key):
@@ -157,22 +161,34 @@ class UI(DisplayableContainer):
 
 	def handle_input(self):
 		key = self.win.getch()
-		if key in (27, 195):  # 27: alt+X, 195: unicode
+		if key is 27 or key >= 128 and key < 256:
+			# Handle special keys like ALT+X or unicode here:
 			keys = [key]
 			previous_load_mode = self.load_mode
 			self.set_load_mode(True)
-			for n in range(8):
+			for n in range(4):
 				getkey = self.win.getch()
 				if getkey is not -1:
 					keys.append(getkey)
+			if len(keys) == 1:
+				keys.append(-1)
 			for key in keys:
 				self.handle_key(key)
 			self.set_load_mode(previous_load_mode)
+			if self.settings.flushinput:
+				curses.flushinp()
 		else:
+			# Handle simple key presses, CTRL+X, etc here:
 			if self.settings.flushinput:
 				curses.flushinp()
 			if key > 0:
-				self.handle_key(key)
+				if key == curses.KEY_MOUSE:
+					self.handle_mouse()
+				elif key == curses.KEY_RESIZE:
+					self.update_size()
+				else:
+					if not self.fm.input_is_blocked():
+						self.handle_key(key)
 
 	def setup(self):
 		"""
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309