summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-24 12:12:43 +0100
committerhut <hut@lavabit.com>2009-12-24 12:12:43 +0100
commita396b3a0a77fb13834c3ed2fe7bd3838a73c5c00 (patch)
tree9221263a6f857e0eb889f0ba3b0fa6bba9e9c021
parent893dd6b4d301fcaccbc37a13746610a10149f0a1 (diff)
downloadranger-a396b3a0a77fb13834c3ed2fe7bd3838a73c5c00.tar.gz
added hints for key-combinations
-rw-r--r--ranger/colorschemes/default.py4
-rw-r--r--ranger/container/commandlist.py51
-rw-r--r--ranger/defaults/keys.py4
-rw-r--r--ranger/gui/colorscheme.py1
-rw-r--r--ranger/gui/defaultui.py5
-rw-r--r--ranger/gui/ui.py15
-rw-r--r--ranger/gui/widgets/console.py1
-rw-r--r--ranger/gui/widgets/statusbar.py31
8 files changed, 95 insertions, 17 deletions
diff --git a/ranger/colorschemes/default.py b/ranger/colorschemes/default.py
index 13a20db9..e3cdb766 100644
--- a/ranger/colorschemes/default.py
+++ b/ranger/colorschemes/default.py
@@ -79,4 +79,8 @@ class Default(ColorScheme):
 #				attr |= bold
 #				fg = white
 
+		if context.text:
+			if context.highlight:
+				attr |= reverse
+
 		return fg, bg, attr
diff --git a/ranger/container/commandlist.py b/ranger/container/commandlist.py
index ab6f1102..d38116eb 100644
--- a/ranger/container/commandlist.py
+++ b/ranger/container/commandlist.py
@@ -1,6 +1,8 @@
 class CommandList(object):
-	"""CommandLists are dictionary-like objects which give you a command
-for a given key combination. CommandLists must be filled before use."""
+	"""
+	CommandLists are dictionary-like objects which give you a command
+	for a given key combination.  CommandLists must be filled before use.
+	"""
 
 	dummy_object = None
 	dummies_in_paths = False
@@ -16,11 +18,13 @@ for a given key combination. CommandLists must be filled before use."""
 		return self.paths[key]
 
 	def rebuild_paths(self):
-		"""Fill the path dictionary with dummie objects.
-We need to know when to clear the keybuffer (when a wrong key is pressed)
-and when to wait for the rest of the key combination. For "gg" we
-will assign "g" to a dummy which tells the program to do the latter
-and wait."""
+		"""
+		Fill the path dictionary with dummie objects.
+		We need to know when to clear the keybuffer (when a wrong key is pressed)
+		and when to wait for the rest of the key combination.  For "gg" we
+		will assign "g" to a dummy which tells the program to do the latter
+		and wait.
+		"""
 		if self.dummies_in_paths:
 			self.remove_dummies()
 		
@@ -51,7 +55,10 @@ and wait."""
 		return all
 
 	def remove_dummies(self):
-		"""remove dummie objects in case you have to rebuild a path dictionary which already contains dummie objects."""
+		"""
+		Remove dummie objects in case you have to rebuild a path dictionary
+		which already contains dummie objects.
+		"""
 		for k in tuple(paths.keys()):
 			if paths[k] == self.dummy_object: del paths[k]
 		self.dummies_in_paths = False
@@ -80,6 +87,19 @@ and wait."""
 		for key in keys:
 			self.paths[key] = cmd
 	
+	def hint(self, text, *keys):
+		"""create a Hint object and assign it to the given key combinations."""
+		if len(keys) == 0: return
+
+		keys = tuple(map(self._str_to_tuple, keys))
+
+		obj = Hint(text, keys)
+
+		self.commandlist.append(obj)
+		for key in keys:
+			self.paths[key] = obj
+
+	
 class Command(object):
 	"""Command objects store information about a command"""
 
@@ -91,4 +111,19 @@ class Command(object):
 	
 	def execute(self, *args):
 		"""Execute the command"""
+	
+#	def __str__(self):
+#		return 'Cmd({0})'.format(str(self.keys))
+
+class Hint(object):
+	"""Hints display text without clearing the keybuffer"""
+
+	keys = []
+	text = ''
+
+	def __init__(self, text, keys):
+		self.keys = keys
+		self.text = text
 
+#	def __str__(self):
+#		return 'Hint({0})'.format(str(self.keys))
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index f40d97d9..68294b22 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -45,9 +45,13 @@ def initialize_commands(command_list):
 	bind('cut', do('cut'))
 	bind('p', do('paste'))
 
+	t_hint = "show_//h//idden //p//review_files //d//irectories_first //a//uto_load_preview //c//ollapse_preview"
+	command_list.hint(t_hint, 't')
 	bind('th', do('toggle_boolean_option', 'show_hidden'))
 	bind('tp', do('toggle_boolean_option', 'preview_files'))
 	bind('td', do('toggle_boolean_option', 'directories_first'))
+	bind('ta', do('toggle_boolean_option', 'auto_load_preview'))
+	bind('tc', do('toggle_boolean_option', 'collapse_preview'))
 
 	bind('cd', do('open_console', ':', 'cd '))
 	bind('f', do('open_console', '>', 'find '))
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index 386c0f85..4fdcaad2 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -9,6 +9,7 @@ CONTEXT_KEYS = [ 'reset', 'error',
 		'space', 'permissions', 'owner', 'group', 'mtime', 'nlink',
 		'scroll', 'all', 'bot', 'top', 'percentage',
 		'marked',
+		'text', 'highlight',
 		'keybuffer']
 
 # colorscheme specification:
diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py
index ba3f79c9..2b1fa188 100644
--- a/ranger/gui/defaultui.py
+++ b/ranger/gui/defaultui.py
@@ -68,5 +68,8 @@ class DefaultUI(UI):
 			self.titlebar.throbber = type(self.titlebar).throbber
 		else:
 			self.titlebar.throbber = string
-
+	
 #		self.win.addnstr(0, self.env.termsize[1]-1, string, 1)
+
+	def hint(self, text=None):
+		self.status.override = text
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 8134231e..07c2de6f 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -105,6 +105,10 @@ class UI(DisplayableContainer):
 
 	def handle_key(self, key):
 		"""Handles key input"""
+
+		if hasattr(self, 'hint'):
+			self.hint()
+
 		self.env.key_append(key)
 
 		if DisplayableContainer.press(self, key):
@@ -121,11 +125,12 @@ class UI(DisplayableContainer):
 			self.env.key_clear()
 			return
 
-		if cmd == self.commandlist.dummy_object:
-			return
-
-		cmd.execute(self.fm, self.env.keybuffer.number)
-		self.env.key_clear()
+		if hasattr(cmd, 'text'):
+			if hasattr(self, 'hint'):
+				self.hint(cmd.text)
+		elif hasattr(cmd, 'execute'):
+				cmd.execute(self.fm, self.env.keybuffer.number)
+				self.env.key_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 1512b763..ee80e639 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -20,6 +20,7 @@ class Console(Widget):
 	original_line = None
 	history = None
 	histories = None
+	override = None
 
 	def __init__(self, win):
 		from ranger.container import CommandList, History
diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py
index 17a5348b..c3c5e74e 100644
--- a/ranger/gui/widgets/statusbar.py
+++ b/ranger/gui/widgets/statusbar.py
@@ -15,6 +15,7 @@ class StatusBar(Widget):
 	owners = {}
 	groups = {}
 	timeformat = '%Y-%m-%d %H:%M'
+	override = None
 
 	def __init__(self, win, filelist=None):
 		Widget.__init__(self, win)
@@ -26,9 +27,33 @@ class StatusBar(Widget):
 		# each item in the returned array looks like:
 		# [ list_with_color_tags,       string       ]
 		# [ ['permissions', 'allowed'], '-rwxr-xr-x' ]
-		left = self._get_left_part()
-		right = self._get_right_part()
-		self._print_result(self._combine_parts(left, right))
+
+		if self.override and isinstance(self.override, str):
+			self._draw_message()
+		else:
+			left = self._get_left_part()
+			right = self._get_right_part()
+			self._print_result(self._combine_parts(left, right))
+	
+	def _draw_message(self):
+		highlight = True
+		space_left = self.wid
+		starting_point = self.x
+		for string in self.override.split('//'):
+			highlight = not highlight
+			if highlight:
+				self.color('in_statusbar', 'text', 'highlight')
+			else:
+				self.color('in_statusbar', 'text')
+
+			try:
+				self.win.addnstr(self.y, starting_point, string, space_left)
+			except:
+				break
+			space_left -= len(string)
+			starting_point += len(string)
+#			if starting_point >= self.wid:
+#				break
 
 	def _get_left_part(self):
 		part = []
percasing all define'd values (uppercase-prefixed should only be enum field qualifiers)' href='/acidbong/suckless/dwm/commit/event.c?id=77f8c075c48e510e064b8f0b7b823a7e1f9f44b7'>77f8c07 ^
c09bf8d ^
ca65478 ^

c09bf8d ^



e6cbe9c ^
95766d6 ^



1173723 ^

8af1d97 ^



c53980c ^
c09bf8d ^






29355bd ^

ca65478 ^
29355bd ^

b9da4b0 ^
dc5d967 ^
b9da4b0 ^
29355bd ^
e995c1b ^



6d22782 ^
1836b67 ^



6d22782 ^

1836b67 ^



05fbbbd ^
e995c1b ^
29355bd ^

2dd5212 ^



29355bd ^
6458d72 ^
7b5638f ^
26157e6 ^
2272df9 ^
26157e6 ^
6d22782 ^



9fce821 ^
26157e6 ^
6d22782 ^

b9da4b0 ^




ca65478 ^
30d9285 ^















ca65478 ^
4ad20ff ^
dc5d967 ^
439e15d ^

439e15d ^
b9da4b0 ^
26157e6 ^
30d9285 ^

70a3e62 ^

2e836ec ^
6a39a49 ^







2e836ec ^
95e8d12 ^
2e836ec ^
95e8d12 ^






30d9285 ^

6a39a49 ^
6828fba ^

b098c94 ^

95e8d12 ^









6a39a49 ^
95e8d12 ^
439e15d ^


ca65478 ^
439e15d ^


26e134b ^

439e15d ^


ca65478 ^
439e15d ^
dc5d967 ^
439e15d ^
b79b5fa ^
439e15d ^

1d85225 ^
3399650 ^
fde45eb ^
da2bbd3 ^
fde45eb ^


439e15d ^


ca65478 ^
83d2390 ^
dc5d967 ^
439e15d ^

59b4a5e ^
c0705ee ^
dba2306 ^
c0705ee ^
439e15d ^



ca65478 ^
0464e42 ^
adaa28a ^

dc5d967 ^
adaa28a ^

2ffdc19 ^
ca65478 ^

2ffdc19 ^
adaa28a ^



2ffdc19 ^
adaa28a ^


ca65478 ^
adaa28a ^

fde45eb ^



adaa28a ^


ca65478 ^
0f3acce ^







ca65478 ^
439e15d ^
dc5d967 ^
439e15d ^









0053620 ^

439e15d ^


ca65478 ^
439e15d ^
dc5d967 ^

439e15d ^



3399650 ^
c09bf8d ^
dba2306 ^
b1701ad ^

3399650 ^


66da153 ^
901b3ed ^
66da153 ^
3399650 ^

d2d394e ^
3399650 ^

c09bf8d ^
d2d394e ^
c0705ee ^
3399650 ^

439e15d ^


ca65478 ^
439e15d ^


0053620 ^

439e15d ^
adaa28a ^
bf35794 ^
adaa28a ^








0f3acce ^
adaa28a ^





ca65478 ^
0464e42 ^
adaa28a ^


0f3acce ^
adaa28a ^

adaa28a ^

3af6434 ^

ee31e38 ^
a73a882 ^
ee31e38 ^
a73a882 ^
adaa28a ^

b6ad663 ^

ca65478 ^
b6ad663 ^







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