summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-02-18 17:39:06 +0100
committerhut <hut@lavabit.com>2010-03-09 14:40:22 +0100
commit91e5b9437e96b067860523c93b7c47998f184161 (patch)
treedc7323dd1f1183bc67feb22db29724c24eef9565
parentdfd2ef35060ab1e4a6a3dab91db25e48696114da (diff)
downloadranger-91e5b9437e96b067860523c93b7c47998f184161.tar.gz
working on the implementation of the new key parser
-rw-r--r--ranger/api/keys.py1
-rw-r--r--ranger/container/__init__.py3
-rw-r--r--ranger/container/environment.py4
-rw-r--r--ranger/container/keymap.py10
-rw-r--r--ranger/defaults/keys.py28
-rw-r--r--ranger/gui/ui.py34
-rw-r--r--ranger/gui/widgets/console.py5
-rw-r--r--ranger/gui/widgets/pager.py11
-rw-r--r--ranger/gui/widgets/taskview.py4
9 files changed, 61 insertions, 39 deletions
diff --git a/ranger/api/keys.py b/ranger/api/keys.py
index 4ac2e18e..a08c57b3 100644
--- a/ranger/api/keys.py
+++ b/ranger/api/keys.py
@@ -21,6 +21,7 @@ from inspect import getargspec, ismethod
 from ranger import RANGERDIR
 from ranger.gui.widgets import console_mode as cmode
 from ranger.container.bookmarks import ALLOWED_KEYS as ALLOWED_BOOKMARK_KEYS
+from ranger.container.keymap import KeyMap, Direction
 
 def make_abbreviations(command_list):
 	def bind(*args, **keywords):
diff --git a/ranger/container/__init__.py b/ranger/container/__init__.py
index b3fe9aff..4c8f08ba 100644
--- a/ranger/container/__init__.py
+++ b/ranger/container/__init__.py
@@ -17,6 +17,5 @@
 used to manage stored data
 """
 from ranger.container.history import History
-from ranger.container.keybuffer import KeyBuffer
-from .keymap import KeyMap
+from .keymap import KeyMap, KeyBuffer
 from .bookmarks import Bookmarks
diff --git a/ranger/container/environment.py b/ranger/container/environment.py
index be1d96c5..b08b357f 100644
--- a/ranger/container/environment.py
+++ b/ranger/container/environment.py
@@ -42,7 +42,7 @@ class Environment(SettingsAware):
 		self.path = abspath(expanduser(path))
 		self.pathway = ()
 		self.directories = {}
-		self.keybuffer = KeyBuffer()
+		self.keybuffer = KeyBuffer(None, None)
 		self.copy = set()
 		self.history = History(self.settings.max_history_size)
 
@@ -56,7 +56,7 @@ class Environment(SettingsAware):
 		if key == curses.KEY_RESIZE:
 			self.keybuffer.clear()
 
-		self.keybuffer.append(key)
+		self.keybuffer.add(key)
 
 	def key_clear(self):
 		"""Clear the keybuffer"""
diff --git a/ranger/container/keymap.py b/ranger/container/keymap.py
index c2aa344f..e1ff06da 100644
--- a/ranger/container/keymap.py
+++ b/ranger/container/keymap.py
@@ -67,9 +67,9 @@ class CommandArgs(object):
 		self.binding = keybuffer.command
 
 	@staticmethod
-	def from_widget(self, widget):
-		return CommandArgs(displayable.fm, \
-				displayable, displayable.env.keybuffer)
+	def from_widget(widget):
+		return CommandArgs(widget.fm, \
+				widget, widget.env.keybuffer)
 
 class KeyMap(Tree):
 	"""Contains a tree with all the keybindings"""
@@ -126,9 +126,11 @@ class Binding(object):
 class KeyBuffer(object):
 	"""The evaluator and storage for pressed keys"""
 	def __init__(self, keymap, direction_keys):
+		self.assign(keymap, direction_keys)
+	
+	def assign(self, keymap, direction_keys):
 		self.keymap = keymap
 		self.direction_keys = direction_keys
-		self.clear()
 
 	def add(self, key):
 		if self.failure:
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index 260ba568..6c24d6d7 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -333,3 +333,31 @@ def _basic_movement(command_list):
 	bind(KEY_UP, wdg.move(relative=-1))
 	bind(KEY_HOME, wdg.move(absolute=0))
 	bind(KEY_END, wdg.move(absolute=-1))
+
+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))
+	return k
+
+def move(arg):
+	arg.fm.move_pointer(relative=arg.direction.down)
+
+def get_ui_keys():
+	k = KeyMap()
+	map = k.add
+
+	map('<dir>', func=move)
+	map('<C-c>', func=fm.exit())
+	return k
+
+ui_keys = get_ui_keys()
+taskview_keys = ui_keys
+pager_keys = ui_keys
+embedded_pager_keys = ui_keys
+console_keys = ui_keys
+directions = get_directions()
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 69acda4b..79552bf2 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -19,14 +19,14 @@ import curses
 import _curses
 
 from .displayable import DisplayableContainer
+from ranger.container.keymap import CommandArgs
 from .mouse_event import MouseEvent
-from ranger.container import CommandList
 
 class UI(DisplayableContainer):
 	is_set_up = False
 	mousemask = curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION
 	load_mode = False
-	def __init__(self, commandlist=None, env=None, fm=None):
+	def __init__(self, keymap=None, env=None, fm=None):
 		import os
 		os.environ['ESCDELAY'] = '25'   # don't know a cleaner way
 
@@ -35,12 +35,13 @@ class UI(DisplayableContainer):
 		if fm is not None:
 			self.fm = fm
 
-		if commandlist is None:
-			self.commandlist = CommandList()
-			self.settings.keys.initialize_commands(self.commandlist)
+		if keymap is None:
+			self.keymap = self.settings.keys.ui_keys
 		else:
-			self.commandlist = commandlist
+			self.keymap = keymap
 		self.win = curses.initscr()
+		self.env.keybuffer.assign(self.keymap, self.settings.keys.directions)
+		self.env.keybuffer.clear()
 
 		DisplayableContainer.__init__(self, None)
 
@@ -132,15 +133,14 @@ class UI(DisplayableContainer):
 		if DisplayableContainer.press(self, key):
 			return
 
-		try:
-			tup = self.env.keybuffer.tuple_without_numbers()
+		kbuf = self.env.keybuffer
 
-			if tup:
-				cmd = self.commandlist[tup]
-			else:
-				return
-		except KeyError:
-			self.env.key_clear()
+		if kbuf.done:
+			cmd = kbuf.command
+		elif kbuf.failure:
+			kbuf.clear()
+			return
+		else:
 			return
 
 		self.env.cmd = cmd
@@ -148,12 +148,12 @@ class UI(DisplayableContainer):
 		if hasattr(cmd, 'show_obj') and hasattr(cmd.show_obj, 'hint'):
 			if hasattr(self, 'hint'):
 				self.hint(cmd.show_obj.hint)
-		elif hasattr(cmd, 'execute'):
+		elif cmd.function:
 			try:
-				cmd.execute_wrap(self)
+				cmd.function(CommandArgs.from_widget(self))
 			except Exception as error:
 				self.fm.notify(error)
-			self.env.key_clear()
+			kbuf.clear()
 
 	def get_next_key(self):
 		"""Waits for key input and returns the pressed key"""
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 87e5a7b5..7ed00a7e 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -54,10 +54,9 @@ class Console(Widget):
 	allow_close = False
 
 	def __init__(self, win):
-		from ranger.container import CommandList, History
+		from ranger.container import History
 		Widget.__init__(self, win)
-		self.commandlist = CommandList()
-		self.settings.keys.initialize_console_commands(self.commandlist)
+		self.keymap = self.settings.keys.console_keys
 		self.clear()
 		self.histories = [None] * 4
 		self.histories[DEFAULT_HISTORY] = History()
diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py
index b3e826e0..03a421cf 100644
--- a/ranger/gui/widgets/pager.py
+++ b/ranger/gui/widgets/pager.py
@@ -18,7 +18,6 @@ The pager displays text and allows you to scroll inside it.
 """
 import re
 from . import Widget
-from ranger.container.commandlist import CommandList
 from ranger.ext.move import move_between
 from ranger import log
 
@@ -42,14 +41,10 @@ class Pager(Widget):
 		self.markup = None
 		self.lines = []
 
-		self.commandlist = CommandList()
-
 		if embedded:
-			keyfnc = self.settings.keys.initialize_embedded_pager_commands
+			self.keymap = self.settings.keys.embedded_pager_keys
 		else:
-			keyfnc = self.settings.keys.initialize_pager_commands
-
-		keyfnc(self.commandlist)
+			self.keymap = self.settings.keys.pager_keys
 
 	def open(self):
 		self.scroll_begin = 0
@@ -166,7 +161,7 @@ class Pager(Widget):
 		try:
 			tup = self.env.keybuffer.tuple_without_numbers()
 			if tup:
-				cmd = self.commandlist[tup]
+				cmd = self.keymap[tup]
 			else:
 				return
 
diff --git a/ranger/gui/widgets/taskview.py b/ranger/gui/widgets/taskview.py
index 6e86465c..f7937e11 100644
--- a/ranger/gui/widgets/taskview.py
+++ b/ranger/gui/widgets/taskview.py
@@ -22,7 +22,6 @@ from collections import deque
 
 from . import Widget
 from ranger.ext.accumulator import Accumulator
-from ranger.container import CommandList
 
 class TaskView(Widget, Accumulator):
 	old_lst = None
@@ -31,8 +30,7 @@ class TaskView(Widget, Accumulator):
 		Widget.__init__(self, win)
 		Accumulator.__init__(self)
 		self.scroll_begin = 0
-		self.commandlist = CommandList()
-		self.settings.keys.initialize_taskview_commands(self.commandlist)
+		self.keymap = self.settings.keys.taskview_keys
 
 	def draw(self):
 		base_clr = deque()
0 4447' href='/akkartik/mu/commit/html/subx/001help.cc.html?h=main&id=5fe060d582d4a82444243a28b18085c971a85628'>5fe060d5 ^
cdfff1a1 ^
5fe060d5 ^
cdfff1a1 ^


5fe060d5 ^
cdfff1a1 ^







































































































































104e521c ^
cdfff1a1 ^















25ad969f ^



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