summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/container/keymap.py27
-rw-r--r--ranger/defaults/keys.py72
-rw-r--r--ranger/ext/tree.py4
-rw-r--r--ranger/gui/ui.py2
-rw-r--r--test/tc_newkeys.py14
5 files changed, 77 insertions, 42 deletions
diff --git a/ranger/container/keymap.py b/ranger/container/keymap.py
index e49da6ee..f9be5e95 100644
--- a/ranger/container/keymap.py
+++ b/ranger/container/keymap.py
@@ -66,6 +66,7 @@ class CommandArgs(object):
 		self.directions = keybuffer.directions
 		self.keys = str(keybuffer)
 		self.matches = keybuffer.matches
+		self.match = keybuffer.matches and keybuffer.matches[0] or None
 		self.binding = keybuffer.command
 
 	@staticmethod
@@ -88,6 +89,8 @@ class KeyMap(Tree):
 			return func
 		return decorator_function
 
+	__call__ = map
+
 	def add_binding(self, *keys, **actions):
 		assert keys
 		bind = Binding(keys, actions)
@@ -181,10 +184,13 @@ class KeyBuffer(object):
 			self.dir_tree_pointer = self.dir_tree_pointer._tree
 			match = self.dir_tree_pointer
 		if isinstance(self.dir_tree_pointer, Binding):
-			if 'alias' in match.actions:
-				self.dir_tree_pointer = self.direction_keys.traverse(
-					match.alias)
-				self._direction_try_to_finish(rec - 1)
+			if match.alias:
+				try:
+					self.dir_tree_pointer = self.direction_keys[match.alias]
+					self._direction_try_to_finish(rec - 1)
+				except KeyError:
+					self.failure = True
+					return None
 			else:
 				direction = match.actions['dir'] * self.direction_quant
 				self.directions.append(direction)
@@ -246,10 +252,13 @@ class KeyBuffer(object):
 		if isinstance(self.tree_pointer, KeyMap):
 			self.tree_pointer = self.tree_pointer._tree
 		if isinstance(self.tree_pointer, Binding):
-			if 'alias' in self.tree_pointer.actions:
-				self.tree_pointer = self.keymap.traverse(
-					translate_keys(self.tree_pointer.actions['alias']))
-				self._try_to_finish(rec - 1)
+			if self.tree_pointer.alias:
+				try:
+					self.tree_pointer = self.keymap[self.tree_pointer.alias]
+					self._try_to_finish(rec - 1)
+				except KeyError:
+					self.failure = True
+					return None
 			else:
 				self.command = self.tree_pointer
 				self.done = True
@@ -285,7 +294,7 @@ class KeyBuffer(object):
 special_keys = {
 	'dir': DIRKEY,
 	'any': ANYKEY,
-	'psv': PASSIVE_ACTION,
+	'bg': PASSIVE_ACTION,
 	'cr': ord("\n"),
 	'enter': ord("\n"),
 	'space': ord(" "),
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index aaa332b9..f2d93c58 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -36,6 +36,7 @@ Check ranger.keyapi for more information
 
 from ranger.api.keys import *
 
+
 def _vimlike_aliases(command_list):
 	bind, alias = make_abbreviations(command_list)
 
@@ -334,31 +335,43 @@ def _basic_movement(command_list):
 	bind(KEY_HOME, wdg.move(absolute=0))
 	bind(KEY_END, wdg.move(absolute=-1))
 
-def get_directions():
-	k = KeyMap()
-	map = k.map
 
+def base_directions():
+	map = KeyMap()
 	map('<down>', dir=Direction(down=1))
 	map('<up>', dir=Direction(down=-1))
 	map('<left>', dir=Direction(right=-1))
 	map('<right>', dir=Direction(right=1))
 
+	return map
+
+def vim():
+	map = KeyMap()
+	map.merge(base_directions())
 	map('j', alias='<down>')
 	map('k', alias='<up>')
 	map('h', alias='<left>')
 	map('l', alias='<right>')
-	return k
 
-def move(arg):
-	arg.fm.move_pointer(relative=arg.direction.down)
+	return map
+
+def system_keys():
+	map = KeyMap()
+	map('Q', fm.exit())
+	map('<mouse>', fm.handle_mouse())
+	map('<C-L>', fm.redraw_window())
+	map('<resize>', fm.resize())
+
+	return map
 
-def get_ui_keys():
-	k = KeyMap()
-	k.merge(system_keys())
-	map = k.map
+def browser_keys():
+	map = KeyMap()
+	map.merge(system_keys())
 
-	map('<dir>', move)
-	map('<C-c>', 'Q', fm.exit())
+	@map('<dir>')
+	def move(arg):
+		arg.fm.move_pointer(relative=arg.direction.down)
+	map(fm.exit(), 'Q')
 
 	# --------------------------------------------------------- history
 	map('H', fm.history_go(-1))
@@ -378,29 +391,38 @@ def get_ui_keys():
 	map('pp', fm.paste())
 	map('po', fm.paste(overwrite=True))
 	map('pl', fm.paste_symlink())
-	map('p<psv>', fm.notify('press //p// once again to confirm pasting' \
+	map('p<bg>', fm.notify('press //p// once again to confirm pasting' \
 			', or //l// to create symlinks'))
 
 	# ---------------------------------------------------- run programs
 	map('s', fm.execute_command(os.environ['SHELL']))
 	map('E', fm.edit_file())
-	map('term', fm.execute_command('x-terminal-emulator', flags='d'))
+	map('.term', fm.execute_command('x-terminal-emulator', flags='d'))
 	map('du', fm.execute_command('du --max-depth=1 -h | less'))
 
-	return k
+	map(':', ';', fm.open_console(cmode.COMMAND))
 
-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
+	return map
+
+def console_keys():
+	map = KeyMap()
+	map.merge(system_keys())
+
+	@map('<any>')
+	def type_key(arg):
+		arg.wdg.type_key(arg.match)
+	
+	map('<up>', wdg.history_move(-1))
+	map('<down>', wdg.history_move(1))
+	map('<tab>', wdg.tab())
 
+#from pprint import pprint
+#pprint(browser_keys()._tree[106].__dict__)
+#raise SystemExit()
 
-ui_keys = get_ui_keys()
+ui_keys = browser_keys()
 taskview_keys = ui_keys
 pager_keys = ui_keys
 embedded_pager_keys = ui_keys
-console_keys = ui_keys
-directions = get_directions()
+console_keys = console_keys()
+directions = vim()
diff --git a/ranger/ext/tree.py b/ranger/ext/tree.py
index d7b08cd7..54505f06 100644
--- a/ranger/ext/tree.py
+++ b/ranger/ext/tree.py
@@ -36,7 +36,7 @@ class Tree(object):
 			newtree._tree = self._tree
 		return newtree
 
-	def merge(self, other, copy=True):
+	def merge(self, other, copy=False):
 		"""Merge another Tree into a copy of self"""
 		def deep_merge(branch, otherbranch):
 			assert isinstance(otherbranch, dict)
@@ -125,7 +125,7 @@ class Tree(object):
 			except TypeError:
 				raise KeyError("trying to enter leaf")
 			except KeyError:
-				raise KeyError(str(char) + " not in tree " + str(tree))
+				raise KeyError(repr(char) + " not in tree " + str(tree))
 		if isinstance(tree, dict):
 			return type(self)(tree, parent=last_tree, key=char)
 		else:
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index a972eca9..2b406113 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -36,7 +36,7 @@ class UI(DisplayableContainer):
 			self.fm = fm
 
 		if keymap is None:
-			self.keymap = self.settings.keys.ui_keys
+			self.keymap = self.settings.keys.browser_keys()
 		else:
 			self.keymap = keymap
 		self.win = curses.initscr()
diff --git a/test/tc_newkeys.py b/test/tc_newkeys.py
index 45ac4e33..a4d69805 100644
--- a/test/tc_newkeys.py
+++ b/test/tc_newkeys.py
@@ -51,7 +51,7 @@ class Test(PressTestCase):
 			return fnc
 
 		km.map('ppp', n(5))
-		km.map('pp<psv>', n(8))
+		km.map('pp<bg>', n(8))
 		km.map('pp<dir>', n(2))
 		directions.map('j', dir=Direction(down=1))
 
@@ -116,6 +116,7 @@ class Test(PressTestCase):
 		directions.map('j', dir=Direction(down=1))
 		directions.map('k', dir=Direction(down=-1))
 		directions.map('<CR>', alias='j')
+		directions.map('@', alias='<CR>')
 
 		base = KeyMap()
 		base.map('a<dir>', add_dirs)
@@ -130,7 +131,7 @@ class Test(PressTestCase):
 		other.map('c<dir>', add_dirs)
 		other.map('g', alias='f')
 
-		km = base.merge(other)
+		km = base.merge(other, copy=True)
 		kb = KeyBuffer(km, directions)
 
 		press = self._mkpress(kb, km)
@@ -142,6 +143,9 @@ class Test(PressTestCase):
 
 		self.assertEqual(5, press('f'))
 		self.assertEqual(5, press('g'))
+		self.assertEqual(press('c<CR>'), press('c@'))
+		self.assertEqual(press('c<CR>'), press('c@'))
+		self.assertEqual(press('c<CR>'), press('c@'))
 
 		for n in range(1, 50):
 			self.assertPressIncomplete(kb, 'y' * n)
@@ -205,19 +209,19 @@ class Test(PressTestCase):
 		# test 1
 		t = Tree('a')
 		u = Tree('b')
-		merged = t.merge(u)
+		merged = t.merge(u, copy=True)
 		self.assertEqual('b', merged._tree)
 
 		# test 2
 		t = Tree('a')
 		u = makeTreeA()
-		merged = t.merge(u)
+		merged = t.merge(u, copy=True)
 		self.assertEqual(u._tree, merged._tree)
 
 		# test 3
 		t = makeTreeA()
 		u = makeTreeB()
-		v = t.merge(u)
+		v = t.merge(u, copy=True)
 
 		self.assertEqual(0, v['aaaX'])
 		self.assertEqual(2, v['aaaY'])
href='/akkartik/mu/blame/html/052tangle.cc.html?h=hlt&id=1d079fc574a35f39fd52e3de23a1c8bfa45238ae'>^
672e3e50 ^
76755b28 ^

4690ce81 ^
0e4a335e ^
4690ce81 ^

2f02189d ^
672e3e50 ^
4690ce81 ^
672e3e50 ^
76755b28 ^

4690ce81 ^
0e4a335e ^
4690ce81 ^

2f02189d ^
672e3e50 ^

eaeb9552 ^
672e3e50 ^
db1f56c8 ^
76755b28 ^
672e3e50 ^
76755b28 ^
eaeb9552 ^


4690ce81 ^
eaeb9552 ^


672e3e50 ^
4690ce81 ^
0cac7022 ^



f344b250 ^
4690ce81 ^
a654e4ec ^
4690ce81 ^
eaeb9552 ^


0cac7022 ^

4690ce81 ^
eaeb9552 ^





0e4a335e ^
0cac7022 ^
dcc060c7 ^

f344b250 ^

0e4a335e ^
f344b250 ^
672e3e50 ^
f344b250 ^

0e4a335e ^
f344b250 ^
672e3e50 ^
0cac7022 ^
0e4a335e ^
eaeb9552 ^


4690ce81 ^
0e4a335e ^






a654e4ec ^
4690ce81 ^

0e4a335e ^

a654e4ec ^
0e4a335e ^
4690ce81 ^

0e4a335e ^



a654e4ec ^
0e4a335e ^
4690ce81 ^

0e4a335e ^





4690ce81 ^
0e4a335e ^


76755b28 ^
dea90217 ^






eaeb9552 ^
dea90217 ^
4690ce81 ^

2f02189d ^
eaeb9552 ^
4690ce81 ^

2f02189d ^
672e3e50 ^
672e3e50 ^


3e1349d2 ^
f344b250 ^
0e4a335e ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^








0e4a335e ^
76755b28 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^
76755b28 ^
0e4a335e ^

3e1349d2 ^
f344b250 ^
0e4a335e ^

f344b250 ^
0e4a335e ^
3e1349d2 ^
f344b250 ^
0e4a335e ^
3e1349d2 ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^













3e1349d2 ^
f344b250 ^
0e4a335e ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^













3e1349d2 ^
f344b250 ^
0e4a335e ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^

672e3e50 ^
3e1349d2 ^
f344b250 ^

672e3e50 ^











3e1349d2 ^
f344b250 ^
0e4a335e ^
f344b250 ^
eaeb9552 ^

3e1349d2 ^
f344b250 ^
0e4a335e ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^
3e1349d2 ^
f344b250 ^
672e3e50 ^
eaeb9552 ^

672e3e50 ^
eaeb9552 ^




672e3e50 ^
eaeb9552 ^





3e1349d2 ^
f344b250 ^
0e4a335e ^

f344b250 ^
eaeb9552 ^
3e1349d2 ^
f344b250 ^
eaeb9552 ^
3e1349d2 ^
f344b250 ^
eaeb9552 ^












3e1349d2 ^
f344b250 ^
0e4a335e ^

f344b250 ^
eaeb9552 ^
3e1349d2 ^
f344b250 ^
eaeb9552 ^
3e1349d2 ^
f344b250 ^
eaeb9552 ^
3e1349d2 ^
0e4a335e ^
eaeb9552 ^





0e4a335e ^
eaeb9552 ^

672e3e50 ^

0e4a335e ^

3e1349d2 ^
f344b250 ^
0e4a335e ^
f344b250 ^
0e4a335e ^
3e1349d2 ^

f344b250 ^
0e4a335e ^
f344b250 ^
0e4a335e ^










3e1349d2 ^
f344b250 ^
0e4a335e ^

f344b250 ^
0e4a335e ^
3e1349d2 ^

f344b250 ^
0e4a335e ^
f344b250 ^
0e4a335e ^










3e1349d2 ^
f344b250 ^
0e4a335e ^

f344b250 ^
0e4a335e ^
3e1349d2 ^

f344b250 ^

0e4a335e ^








2f02189d ^










f344b250 ^
2f02189d ^





f344b250 ^
2f02189d ^









672e3e50 ^


a654e4ec ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496