summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/container/keymap.py22
-rw-r--r--ranger/defaults/keys.py53
-rw-r--r--test/tc_newkeys.py12
3 files changed, 78 insertions, 9 deletions
diff --git a/ranger/container/keymap.py b/ranger/container/keymap.py
index e1ff06da..70faa0d0 100644
--- a/ranger/container/keymap.py
+++ b/ranger/container/keymap.py
@@ -12,6 +12,7 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
+import curses
 from string import ascii_lowercase
 from inspect import isfunction, getargspec
 from ranger.ext.tree import Tree
@@ -121,7 +122,7 @@ class Binding(object):
 		except KeyError:
 			self.alias = None
 		else:
-			self.alias = translate_keys(alias)
+			self.alias = tuple(translate_keys(alias))
 
 class KeyBuffer(object):
 	"""The evaluator and storage for pressed keys"""
@@ -173,9 +174,12 @@ class KeyBuffer(object):
 		if rec <= 0:
 			self.failure = True
 			return None
-		if not isinstance(self.dir_tree_pointer, dict):
+		match = self.dir_tree_pointer
+		assert isinstance(match, (Binding, dict, KeyMap))
+		if isinstance(match, KeyMap):
+			self.dir_tree_pointer = self.dir_tree_pointer._tree
 			match = self.dir_tree_pointer
-			assert isinstance(match, Binding)
+		if isinstance(self.dir_tree_pointer, Binding):
 			if 'alias' in match.actions:
 				self.dir_tree_pointer = self.direction_keys.traverse(
 					match.alias)
@@ -204,7 +208,7 @@ class KeyBuffer(object):
 
 	def _do_eval_command(self, key):
 		try:
-			assert isinstance(self.tree_pointer, dict)
+			assert isinstance(self.tree_pointer, dict), self.tree_pointer
 			self.tree_pointer = self.tree_pointer[key]
 		except TypeError:
 			print(self.tree_pointer)
@@ -278,6 +282,16 @@ key_map = {
 	'enter': ord("\n"),
 	'space': ord(" "),
 	'space': ord(" "),
+	'down': curses.KEY_DOWN,
+	'up': curses.KEY_UP,
+	'left': curses.KEY_LEFT,
+	'right': curses.KEY_RIGHT,
+	'mouse': curses.KEY_MOUSE,
+	'resize': curses.KEY_RESIZE,
+	'pagedown': curses.KEY_NPAGE,
+	'pageup': curses.KEY_PPAGE,
+	'home': curses.KEY_HOME,
+	'end': curses.KEY_END,
 	'tab': ord('\t'),
 }
 for char in ascii_lowercase:
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index 6c24d6d7..e6d2b0cc 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -338,10 +338,15 @@ def get_directions():
 	k = KeyMap()
 	map = k.add
 
-	map('j', dir=Direction(down=1))
-	map('k', dir=Direction(down=-1))
-	map('h', dir=Direction(right=-1))
-	map('l', dir=Direction(right=1))
+	map('<down>', dir=Direction(down=1))
+	map('<up>', dir=Direction(down=-1))
+	map('<left>', dir=Direction(right=-1))
+	map('<right>', dir=Direction(right=1))
+
+	map('j', alias='<down>')
+	map('k', alias='<up>')
+	map('h', alias='<left>')
+	map('l', alias='<right>')
 	return k
 
 def move(arg):
@@ -349,12 +354,50 @@ def move(arg):
 
 def get_ui_keys():
 	k = KeyMap()
+	k.merge(system_keys())
 	map = k.add
 
 	map('<dir>', func=move)
-	map('<C-c>', func=fm.exit())
+	map('<C-c>', 'Q', func=fm.exit())
+
+	# --------------------------------------------------------- history
+	map('H', func=fm.history_go(-1))
+	map('L', func=fm.history_go(1))
+
+	# ----------------------------------------------- tagging / marking
+	map('t', func=fm.tag_toggle())
+	map('T', func=fm.tag_remove())
+
+	map(' ', func=fm.mark(toggle=True))
+	map('v', func=fm.mark(all=True, toggle=True))
+	map('V', func=fm.mark(all=True, val=False))
+
+	# ------------------------------------------ file system operations
+	map('yy', func=fm.copy())
+	map('dd', func=fm.cut())
+	map('pp', func=fm.paste())
+	map('po', func=fm.paste(overwrite=True))
+	map('pl', func=fm.paste_symlink())
+	map('p', hint='press //p// once again to confirm pasting' \
+			', func=or //l// to create symlinks')
+
+	# ---------------------------------------------------- run programs
+	map('s', func=fm.execute_command(os.environ['SHELL']))
+	map('E', func=fm.edit_file())
+	map('term', func=fm.execute_command('x-terminal-emulator', flags='d'))
+	map('du', func=fm.execute_command('du --max-depth=1 -h | less'))
+
 	return k
 
+def system_keys():
+	k = KeyMap()
+	k.map(fm.exit(), 'Q')
+	k.map(fm.handle_mouse(), '<mouse>')
+	k.map(fm.redraw_window(), '<C-L>')
+	k.map(fm.resize(), '<resize>')
+	return k
+
+
 ui_keys = get_ui_keys()
 taskview_keys = ui_keys
 pager_keys = ui_keys
diff --git a/test/tc_newkeys.py b/test/tc_newkeys.py
index 8f5422a0..0922029e 100644
--- a/test/tc_newkeys.py
+++ b/test/tc_newkeys.py
@@ -380,10 +380,22 @@ class Test(PressTestCase):
 			return arg.direction.down
 
 		directions.add('j', dir=Direction(down=1))
+		directions.add('s', alias='j')
 		directions.add('k', dir=Direction(down=-1))
 		km.add('<dir>', func=move)
 
 		self.assertEqual(1, press('j'))
+		self.assertEqual(1, press('j'))
+		self.assertEqual(1, press('j'))
+		self.assertEqual(1, press('j'))
+		self.assertEqual(1, press('j'))
+		self.assertEqual(1, press('s'))
+		self.assertEqual(1, press('s'))
+		self.assertEqual(1, press('s'))
+		self.assertEqual(1, press('s'))
+		self.assertEqual(1, press('s'))
+		self.assertEqual(-1, press('k'))
+		self.assertEqual(-1, press('k'))
 		self.assertEqual(-1, press('k'))
 
 		km.add('k', func=lambda _: 'love')