diff options
author | sterni <sternenseemann@systemli.org> | 2021-05-25 06:00:29 +0200 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2021-05-25 06:00:29 +0200 |
commit | f7be01b88a14ccc3d406b13068e92eb9f33baa82 (patch) | |
tree | e9c4ed040dd2adbf78b418f55775973944aa00b2 | |
parent | c0d6cc482f33a38d29292f88a73fcf00e0d77f36 (diff) |
Clear the line if Down is pressed at the most recent history entry
This mimicks the behavior familiar from most shells. We also make sure that this doesn't happen when we hit the oldest history entry -- in that case we will just do nothing if Up is pressed. To implement this correctly we need to distinguish between a position in the history and no position in the history. We encode the latter using `None` and just call `reset_history_index()` in case we encounter it to reacquire a point of reference.
-rw-r--r-- | saneterm/terminal.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/saneterm/terminal.py b/saneterm/terminal.py index c3ae3cf..7ad301a 100644 --- a/saneterm/terminal.py +++ b/saneterm/terminal.py @@ -161,17 +161,28 @@ class Terminal(Gtk.Window): self.hist_index = -1 def history(self, termview, idx): - # Backup index and restore it if no entry with new index exists. + if self.hist_index is None: + self.reset_history_index() + + # Backup index and restore it if we hit the beginning of the history backup_index = self.hist_index self.hist_index += idx entry = self.hist.get_entry(self.pty.master, self.hist_index) if entry is None: - self.hist_index = backup_index - else: - self.termview.emit("kill-after-output") - self.termview.emit("insert-at-cursor", entry) + if idx > 0: + # we are going back in time. if there are no older + # entries, restore history index and bail out. + self.hist_index = backup_index + return + else: + # if we arrive at the present, just clear the line + self.hist_index = None + entry = "" + + self.termview.emit("kill-after-output") + self.termview.emit("insert-at-cursor", entry) def autoscroll(self, widget, rect): if not self.config['autoscroll']: |