summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-17 19:35:46 +0100
committerhut <hut@lavabit.com>2009-12-17 19:35:46 +0100
commit277a7026164384ec453bbb8c59c91996e8262d18 (patch)
treee677060ebe2cb0e4bdfd370849de7d5beab638be
parent3dbefa71785bf61b8f28d4a780064f3f4e04dcb5 (diff)
downloadranger-277a7026164384ec453bbb8c59c91996e8262d18.tar.gz
added history to console
-rw-r--r--ranger/defaults/keys.py2
-rw-r--r--ranger/gui/widgets/console.py61
2 files changed, 47 insertions, 16 deletions
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py
index acfe1178..706e36e8 100644
--- a/ranger/defaults/keys.py
+++ b/ranger/defaults/keys.py
@@ -98,6 +98,8 @@ def initialize_console_commands(command_list):
 		return lambda con: getattr(con.fm, method)(*args, **kw)
 
 	# movement
+	bind(curses.KEY_UP, do('history_move', -1))
+	bind(curses.KEY_DOWN, do('history_move', 1))
 	bind(ctrl('b'), curses.KEY_LEFT, do('move', relative = -1))
 	bind(ctrl('f'), curses.KEY_RIGHT, do('move', relative = 1))
 	bind(ctrl('a'), curses.KEY_HOME, do('move', absolute = 0))
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index ca21189c..bed9f031 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -5,6 +5,9 @@ from ranger import commands
 import curses
 from collections import deque
 
+DEFAULT_HISTORY = 0
+SEARCH_HISTORY = 1
+
 class Console(Widget):
 	mode = None
 	visible = False
@@ -14,16 +17,21 @@ class Console(Widget):
 	copy = ''
 	tab_deque = None
 	original_line = None
+	history = None
+	histories = None
 
 	def __init__(self, win):
-		from ranger.container import CommandList
+		from ranger.container import CommandList, History
 		Widget.__init__(self, win)
 		self.commandlist = CommandList()
 		self.settings.keys.initialize_console_commands(self.commandlist)
 		self.clear()
+		self.histories = [None] * 2
+		self.histories[DEFAULT_HISTORY] = History()
+		self.histories[SEARCH_HISTORY] = History()
 	
 	def init(self):
-		pass
+		"""override this. Called directly after class change"""
 
 	def draw(self):
 		if self.mode is None:
@@ -43,16 +51,19 @@ class Console(Widget):
 		self.last_cursor_mode = curses.curs_set(1)
 		self.mode = mode
 		self.__class__ = self.mode_classes[mode]
+		self.history = self.histories[DEFAULT_HISTORY]
 		self.init()
 		self.tab_deque = None
 		self.focused = True
 		self.visible = True
 		self.line = string
 		self.pos = len(string)
+		self.history.add('')
 		return True
 
 	def close(self):
 		curses.curs_set(self.last_cursor_mode)
+		self.add_to_history()
 		self.clear()
 		self.__class__ = Console
 		self.focused = False
@@ -93,6 +104,25 @@ class Console(Widget):
 		self.pos += len(key)
 		self.on_line_change()
 
+	def history_move(self, n):
+		from ranger.container.history import HistoryEmptyException
+		try:
+			current = self.history.current()
+		except HistoryEmptyException:
+			pass
+		else:
+			if self.line != current and self.line != self.history.top():
+				self.history.modify(self.line)
+			self.history.move(n)
+			current = self.history.current()
+			if self.line != current:
+				self.line = self.history.current()
+				self.pos = len(self.line)
+	
+	def add_to_history(self):
+		self.history.fast_forward()
+		self.history.modify(self.line)
+
 	def move(self, relative = 0, absolute = None):
 		if absolute is not None:
 			if absolute < 0:
@@ -144,7 +174,6 @@ class Console(Widget):
 
 	def execute(self):
 		self.tab_deque = None
-		self.clear()
 		self.close()
 
 	def tab(self):
@@ -153,6 +182,7 @@ class Console(Widget):
 	def on_line_change(self):
 		pass
 
+
 class CommandConsole(Console):
 	prompt = ':'
 
@@ -212,8 +242,13 @@ class QuickCommandConsole(CommandConsole):
 		if cmd and cmd.quick_open():
 			self.execute()
 
+
 class SearchConsole(Console):
 	prompt = '/'
+
+	def init(self):
+		self.history = self.histories[SEARCH_HISTORY]
+
 	def execute(self):
 		import re
 		if self.fm.env.pwd:
@@ -226,21 +261,15 @@ class SearchConsole(Console):
 
 class OpenConsole(Console):
 	prompt = '!'
-#	def execute(self):
-#		line = self.line
-#		if line[0] == '!':
-#			self.fm.execute_file(tuple(line[1:].split()) + (self.fm.env.cf.path, ))
-#		else:
-#			self.fm.execute_file(tuple(line.split()) + (self.fm.env.cf.path, ), flags='d')
-#		Console.execute(self)
 
 
 class QuickOpenConsole(Console):
+
 	"""The QuickOpenConsole allows you to open files with
-pre-defined programs and modes very quickly. By adding flags
-to the command, you can specify precisely how the program is run,
-ie. the d-flag will run it detached from the filemanager.
-"""
+	pre-defined programs and modes very quickly. By adding flags
+	to the command, you can specify precisely how the program is run,
+	ie. the d-flag will run it detached from the filemanager.
+	"""
 
 	prompt = 'open with: '
 
@@ -256,8 +285,8 @@ ie. the d-flag will run it detached from the filemanager.
 
 	def _get_app_flags_mode(self):
 		"""extracts the application, flags and mode from
-a string entered into the "openwith_quick" console.
-"""
+		a string entered into the "openwith_quick" console.
+		"""
 		# examples:
 		# "mplayer d 1" => ("mplayer", "d", 1)
 		# "aunpack 4" => ("aunpack", "", 4)
ram <vc@akkartik.com> 2017-03-07 01:41:48 -0800 3761' href='/akkartik/mu/commit/html/075channel.mu.html?h=main&id=9e751bb8c0cdf771d34c839cb6591d892b8e62de'>9e751bb8 ^
204dae92 ^

9e751bb8 ^

204dae92 ^























201458e3 ^
204dae92 ^




201458e3 ^

204dae92 ^






201458e3 ^
204dae92 ^



7be07a6b ^
204dae92 ^




9e751bb8 ^
204dae92 ^
9e751bb8 ^

204dae92 ^
9e751bb8 ^





204dae92 ^










9e751bb8 ^




204dae92 ^

















9e751bb8 ^
204dae92 ^
9e751bb8 ^

204dae92 ^
9e751bb8 ^






204dae92 ^











9e751bb8 ^




204dae92 ^









201458e3 ^
204dae92 ^



9e751bb8 ^


204dae92 ^




9e751bb8 ^




204dae92 ^

9e751bb8 ^

204dae92 ^




201458e3 ^
204dae92 ^
9e751bb8 ^



204dae92 ^

9e751bb8 ^

204dae92 ^




201458e3 ^

204dae92 ^
9e751bb8 ^



204dae92 ^

9e751bb8 ^

204dae92 ^





201458e3 ^
204dae92 ^

201458e3 ^
204dae92 ^

9e751bb8 ^








204dae92 ^

9e751bb8 ^



204dae92 ^




9e751bb8 ^




204dae92 ^

9e751bb8 ^

204dae92 ^




201458e3 ^
204dae92 ^

9e751bb8 ^


204dae92 ^

9e751bb8 ^

204dae92 ^




201458e3 ^
204dae92 ^

9e751bb8 ^


204dae92 ^

9e751bb8 ^

204dae92 ^




201458e3 ^
204dae92 ^
201458e3 ^
204dae92 ^
9e751bb8 ^


204dae92 ^

9e751bb8 ^

204dae92 ^































7be07a6b ^
204dae92 ^


7be07a6b ^
204dae92 ^

9e751bb8 ^



204dae92 ^





201458e3 ^
204dae92 ^








e520e798 ^
201458e3 ^
204dae92 ^





9e751bb8 ^




204dae92 ^





201458e3 ^
204dae92 ^







201458e3 ^
204dae92 ^




9e751bb8 ^













































204dae92 ^




9e751bb8 ^





204dae92 ^
9e751bb8 ^




201458e3 ^
9e751bb8 ^





204dae92 ^
9e751bb8 ^





204dae92 ^
9e751bb8 ^






204dae92 ^
9e751bb8 ^
204dae92 ^

9e751bb8 ^
204dae92 ^


201458e3 ^
204dae92 ^

201458e3 ^
204dae92 ^
9e751bb8 ^



204dae92 ^
201458e3 ^
204dae92 ^
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566