summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-03-29 02:15:22 +0200
committerhut <hut@lavabit.com>2010-03-29 02:15:22 +0200
commitf5e9c01ec9f092366bd7de2ec5be973b312ed159 (patch)
tree514d3cfc419d2d767443b7136a096c39bf528904
parent6ae68da4b0c341cbd49f05bb02b979bec4377d20 (diff)
downloadranger-f5e9c01ec9f092366bd7de2ec5be973b312ed159.tar.gz
added option "save_console_history"
-rw-r--r--ranger/defaults/options.py3
-rw-r--r--ranger/gui/ui.py2
-rw-r--r--ranger/gui/widgets/console.py34
-rw-r--r--ranger/shared/settings.py1
4 files changed, 33 insertions, 7 deletions
diff --git a/ranger/defaults/options.py b/ranger/defaults/options.py
index ce010195..00a248c5 100644
--- a/ranger/defaults/options.py
+++ b/ranger/defaults/options.py
@@ -50,6 +50,9 @@ preview_directories = True
 max_filesize_for_preview = 300 * 1024  # 300kb
 collapse_preview = True
 
+# Save the console history on exit?
+save_console_history = True
+
 # Draw borders around columns?
 draw_borders = False
 draw_bookmark_borders = True
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index 3e8f9e10..ba8acea9 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -111,8 +111,8 @@ class UI(DisplayableContainer):
 
 	def destroy(self):
 		"""Destroy all widgets and turn off curses"""
-		DisplayableContainer.destroy(self)
 		self.suspend()
+		DisplayableContainer.destroy(self)
 
 	def handle_mouse(self):
 		"""Handles mouse input"""
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 0502e624..ed121d4c 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -25,8 +25,9 @@ from collections import deque
 from . import Widget
 from ranger.defaults import commands
 from ranger.gui.widgets.console_mode import is_valid_mode, mode_to_class
-from ranger import log
+from ranger import log, relpath_conf
 from ranger.ext.shell_escape import shell_quote
+import ranger
 
 DEFAULT_HISTORY = 0
 SEARCH_HISTORY = 1
@@ -52,6 +53,7 @@ class Console(Widget):
 	histories = None
 	override = None
 	allow_close = False
+	historypaths = []
 
 	def __init__(self, win):
 		from ranger.container import CommandList, History
@@ -59,11 +61,31 @@ class Console(Widget):
 		self.commandlist = CommandList()
 		self.settings.keys.initialize_console_commands(self.commandlist)
 		self.clear()
-		self.histories = [None] * 4
-		self.histories[DEFAULT_HISTORY] = History()
-		self.histories[SEARCH_HISTORY] = History()
-		self.histories[QUICKOPEN_HISTORY] = History()
-		self.histories[OPEN_HISTORY] = History()
+		self.histories = []
+		# load histories from files
+		if not ranger.arg.clean:
+			self.historypaths = [relpath_conf(x) for x in \
+				('history', 'history_search', 'history_qopen', 'history_open')]
+			for i, path in enumerate(self.historypaths):
+				hist = History(self.settings.max_history_size)
+				self.histories.append(hist)
+				if ranger.arg.clean: continue
+				try: f = open(path, 'r')
+				except: continue
+				for line in f:
+					hist.add(line[:-1])
+				f.close()
+
+	def destroy(self):
+		# save histories from files
+		if ranger.arg.clean or not self.settings.save_console_history:
+			return
+		for i, path in enumerate(self.historypaths):
+			try: f = open(path, 'w')
+			except: continue
+			for entry in self.histories[i]:
+				f.write(entry + '\n')
+			f.close()
 
 	def init(self):
 		"""override this. Called directly after class change"""
diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py
index 63e9d4e4..88c2dfb3 100644
--- a/ranger/shared/settings.py
+++ b/ranger/shared/settings.py
@@ -24,6 +24,7 @@ ALLOWED_SETTINGS = {
 	'show_hidden': bool,
 	'show_cursor': bool,
 	'autosave_bookmarks': bool,
+	'save_console_history': bool,
 	'collapse_preview': bool,
 	'draw_borders': bool,
 	'draw_bookmark_borders': bool,
committer Kartik K. Agaram <vc@akkartik.com> 2017-12-30 21:12:06 -0800 4171' href='/akkartik/mu/commit/Readme.md?h=hlt&id=d214836b78b124b2e33d9400b2285ce84a18af84'>d214836b ^
ddf378d4 ^
f3e55e7e ^


d3869932 ^
a526d013 ^
2c9aa92f ^
2d05f43c ^
a232af2f ^



4977f1e0 ^
0c9dacf3 ^

ddf378d4 ^
beab6db0 ^
28fd2290 ^
2c9aa92f ^
c5b93055 ^
28fd2290 ^
2c9aa92f ^
25896f17 ^
32241605 ^
1ead3562 ^
14b33e59 ^
ddf378d4 ^

14b33e59 ^
28fd2290 ^
8b9f1750 ^
28fd2290 ^
14b33e59 ^
88783265 ^
32983f88 ^


797a46d5 ^
28fd2290 ^
bc643692 ^
28fd2290 ^
797a46d5 ^
76f94980 ^


32241605 ^
14b33e59 ^
28fd2290 ^
ef401599 ^

76f94980 ^
32241605 ^
28fd2290 ^
d4b4d018 ^
32241605 ^







1ead3562 ^
32241605 ^


1ead3562 ^
32241605 ^
1ead3562 ^
32241605 ^
57c5d9b2 ^
5914514b ^
32241605 ^
c7db6a16 ^


27ba0937 ^
687f871a ^
5914514b ^
76f94980 ^

32241605 ^


1ead3562 ^
32241605 ^



1ead3562 ^
32241605 ^
af7dd1a8 ^



32241605 ^




1ead3562 ^
32241605 ^
5914514b ^

612c48da ^
ef401599 ^
8f9ec2fb ^

28fd2290 ^
8f9ec2fb ^

28fd2290 ^
8f9ec2fb ^
ef401599 ^

28fd2290 ^
ef401599 ^
28fd2290 ^
ef401599 ^


1ead3562 ^
ef401599 ^



76f94980 ^

8aa1baa4 ^
ef401599 ^
1ead3562 ^
ef401599 ^


b0b48673 ^





56356de8 ^
b0b48673 ^
56356de8 ^
ef401599 ^
56356de8 ^

ef401599 ^
8f9ec2fb ^

f8a4a457 ^



bdd16778 ^
f8a4a457 ^



bdd16778 ^
f8a4a457 ^




d214836b ^





f8a4a457 ^


88783265 ^

d4b4d018 ^
28fd2290 ^
5497090a ^
d4b4d018 ^
32983f88 ^
28fd2290 ^
d4b4d018 ^
f00fc595 ^
8f9ec2fb ^


d4b4d018 ^



e9e06638 ^


a3c025c5 ^
28fd2290 ^
88783265 ^
32983f88 ^
a3c025c5 ^
28fd2290 ^
14b33e59 ^

2c9aa92f ^
8aa1baa4 ^
797a46d5 ^

1d079fc5 ^
797a46d5 ^


8aa1baa4 ^

12816015 ^
797a46d5 ^

32983f88 ^
002cbf13 ^
1d079fc5 ^
4e6778d7 ^
28fd2290 ^
4f9f75dd ^
28fd2290 ^
002cbf13 ^



32983f88 ^

f192d655 ^
28fd2290 ^
4f9f75dd ^
f192d655 ^












28fd2290 ^
f192d655 ^
32983f88 ^


f192d655 ^


23d3a022 ^


f192d655 ^


c7db6a16 ^
383d5bea ^
28fd2290 ^
a90faae9 ^
28fd2290 ^
383d5bea ^


1ead3562 ^
383d5bea ^
1ead3562 ^
5ccf2653 ^


383d5bea ^
fd432e7d ^

383d5bea ^
e9e06638 ^

1ead3562 ^
e9e06638 ^



1ead3562 ^
e9e06638 ^

4693839e ^


224972ee ^
4693839e ^

fe0c9163 ^

e9e06638 ^
c7db6a16 ^




af7dd1a8 ^


c7db6a16 ^
1d581c4f ^
c7db6a16 ^




1d581c4f ^
95f0addb ^
ddf378d4 ^
1d581c4f ^
c442a5ad ^










1d581c4f ^
5763322b ^




1d581c4f ^





6bf34cf3 ^
14b33e59 ^


7efed68b ^
14b33e59 ^

7efed68b ^

14b33e59 ^




7efed68b ^
14b33e59 ^
7efed68b ^
14b33e59 ^

7efed68b ^
95fe5a4a ^

14b33e59 ^



7efed68b ^
14b33e59 ^
7efed68b ^

14b33e59 ^



7e85c336 ^
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