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,
a> 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