diff options
author | hut <hut@lavabit.com> | 2010-03-29 02:15:22 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-03-29 02:15:22 +0200 |
commit | f5e9c01ec9f092366bd7de2ec5be973b312ed159 (patch) | |
tree | 514d3cfc419d2d767443b7136a096c39bf528904 /ranger | |
parent | 6ae68da4b0c341cbd49f05bb02b979bec4377d20 (diff) | |
download | ranger-f5e9c01ec9f092366bd7de2ec5be973b312ed159.tar.gz |
added option "save_console_history"
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/defaults/options.py | 3 | ||||
-rw-r--r-- | ranger/gui/ui.py | 2 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 34 | ||||
-rw-r--r-- | ranger/shared/settings.py | 1 |
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, |