diff options
author | Sören Tempel <soeren+git@soeren-tempel.net> | 2021-05-16 21:01:48 +0200 |
---|---|---|
committer | Sören Tempel <soeren+git@soeren-tempel.net> | 2021-05-16 21:01:48 +0200 |
commit | af0954f768cc332dc7244acc441021170ad9efca (patch) | |
tree | 9822e7eaf99bcef80c5f6043205b7f381b071727 | |
parent | cb70a6351e2476049f26d2b7de85d33dc3177101 (diff) |
Add support for 9term-like control-u key binding
-rw-r--r-- | src/input.py | 3 | ||||
-rw-r--r-- | src/terminal.py | 27 |
2 files changed, 29 insertions, 1 deletions
diff --git a/src/input.py b/src/input.py index c6822bd..6798ad1 100644 --- a/src/input.py +++ b/src/input.py @@ -2,11 +2,12 @@ import gi gi.require_version("Gtk", "3.0") from gi.repository import Gtk +from gi.repository import GObject class KeyBindings(): stylesheet = b""" @binding-set saneterm-key-bindings { - bind "<ctrl>h" { "delete-from-cursor" (chars, -1) }; + bind "<ctrl>u" { "kill-after-output" () }; } * { diff --git a/src/terminal.py b/src/terminal.py index 52435a6..bcdd2b7 100644 --- a/src/terminal.py +++ b/src/terminal.py @@ -11,6 +11,7 @@ gi.require_version("Gtk", "3.0") from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GLib +from gi.repository import GObject WIN_TITLE = "saneterm" TERM = "dumb" @@ -64,6 +65,7 @@ class Terminal(Gtk.Window): end = self.textbuffer.get_end_iter() self.last_mark = self.textbuffer.create_mark(None, end, True) + self.last_output_mark = None # Block-wise reading from the PTY requires an incremental decoder. self.decoder = codecs.getincrementaldecoder('UTF-8')() @@ -71,8 +73,22 @@ class Terminal(Gtk.Window): bindings = input.KeyBindings() bindings.apply(self.textview) + self.bind_custom_signals() self.add(self.textview) + def bind_custom_signals(self): + signals = { + "kill-after-output": self.kill_after_output, + } + + for signal in signals.items(): + name, func = signal + GObject.signal_new(name, self.textview, + GObject.SIGNAL_ACTION, GObject.TYPE_NONE, + ()) + + self.textview.connect(name, func) + def handle_pty(self, master): # XXX: Should be possible to read more than one byte here. data = os.read(master, 1) @@ -84,6 +100,7 @@ class Terminal(Gtk.Window): end = self.textbuffer.get_end_iter() self.last_mark = self.textbuffer.create_mark(None, end, True) + self.last_output_mark = self.last_mark return GLib.SOURCE_CONTINUE @@ -97,3 +114,13 @@ class Terminal(Gtk.Window): text = buffer.get_text(start, end, True) os.write(self.pty.master, text.encode("UTF-8")) self.last_mark = buffer.create_mark(None, end, True) + + def kill_after_output(self, textview): + if self.last_output_mark is None: + return + buffer = textview.get_buffer() + + start = buffer.get_iter_at_mark(self.last_output_mark) + end = buffer.get_end_iter() + + buffer.delete(start, end) |