diff options
author | hut <hut@lavabit.com> | 2011-10-09 22:11:35 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-10-09 22:11:35 +0200 |
commit | 376dfe2bb4dac316814c654ec55a3ad6ed3eff1f (patch) | |
tree | 36ed613195af7b8e408ed3c20f434c5dc6bf19b6 /ranger | |
parent | 2155330507a0d750b92acabbeed488d2f958144c (diff) | |
download | ranger-376dfe2bb4dac316814c654ec55a3ad6ed3eff1f.tar.gz |
widgets.console: Improved command history
No entries should be lost now. Entries are only added or moved to the top of the stack when you enter them again.
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/container/history.py | 14 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 15 |
2 files changed, 19 insertions, 10 deletions
diff --git a/ranger/container/history.py b/ranger/container/history.py index d7a45500..62965a31 100644 --- a/ranger/container/history.py +++ b/ranger/container/history.py @@ -18,10 +18,16 @@ class HistoryEmptyException(Exception): class History(object): def __init__(self, maxlen=None, unique=True): - self._history = [] - self._index = 0 - self.maxlen = maxlen - self.unique = unique + if isinstance(maxlen, History): + self._history = list(maxlen._history) + self._index = maxlen._index + self.maxlen = maxlen.maxlen + self.unique = maxlen.unique + else: + self._history = [] + self._index = 0 + self.maxlen = maxlen + self.unique = unique def add(self, item): # Remove everything after index diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 2a7a34d3..5fcea9d3 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -25,8 +25,7 @@ from collections import deque from . import Widget from ranger.ext.direction import Direction from ranger.ext.widestring import uwid, WideString -from ranger.container import History -from ranger.container.history import HistoryEmptyException +from ranger.container.history import History, HistoryEmptyException import ranger class Console(Widget): @@ -38,6 +37,7 @@ class Console(Widget): tab_deque = None original_line = None history = None + history_backup = None override = None allow_close = False historypath = None @@ -57,6 +57,7 @@ class Console(Widget): for line in f: self.history.add(line[:-1]) f.close() + self.history_backup = History(self.history) def destroy(self): # save history to files @@ -68,7 +69,7 @@ class Console(Widget): except: pass else: - for entry in self.history: + for entry in self.history_backup: f.write(entry + '\n') f.close() @@ -111,7 +112,8 @@ class Console(Widget): self.pos = len(string) if position is not None: self.pos = min(self.pos, position) - self.history.fast_forward() + self.history_backup.fast_forward() + self.history = History(self.history_backup) self.history.add('') return True @@ -199,8 +201,9 @@ class Console(Widget): self.pos = len(self.line) def add_to_history(self): - self.history.fast_forward() - self.history.modify(self.line, unique=True) + self.history_backup.fast_forward() + self.history_backup.add(self.line) + self.history = History(self.history_backup) def move(self, **keywords): direction = Direction(keywords) |