From 36ea4b0b19370182110cf3f76aab99e428ddb46d Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Sat, 22 May 2021 03:05:11 +0200 Subject: Rename input.py to keys.py Also move default control character mappings to this module. --- saneterm/input.py | 37 ------------------------------------- saneterm/keys.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ saneterm/terminal.py | 13 +++---------- 3 files changed, 49 insertions(+), 47 deletions(-) delete mode 100644 saneterm/input.py create mode 100644 saneterm/keys.py diff --git a/saneterm/input.py b/saneterm/input.py deleted file mode 100644 index 29658c3..0000000 --- a/saneterm/input.py +++ /dev/null @@ -1,37 +0,0 @@ -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 "u" { "kill-after-output" () }; - bind "a" { "move-input-start" () }; - bind "e" { "move-input-end" () }; - } - - * { - -gtk-key-bindings: saneterm-key-bindings; - } - """ - - def __init__(self, widget): - self.provider = Gtk.CssProvider() - self.provider.load_from_data(self.stylesheet) - - style_ctx = widget.get_style_context() - style_ctx.add_provider(self.provider, - Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) - - def add_bind(self, key, signal, arg): - bindings = self.__binding_set() - # Using Gtk.BindingEntry.add_signall() would be preferable - # https://gitlab.gnome.org/GNOME/pygobject/-/issues/474 - Gtk.BindingEntry().add_signal_from_string(bindings, - F'bind "{key}" {{ "{signal}" ({arg}) }};') - - def __binding_set(self): - return Gtk.BindingSet.find("saneterm-key-bindings") - diff --git a/saneterm/keys.py b/saneterm/keys.py new file mode 100644 index 0000000..7cb88d7 --- /dev/null +++ b/saneterm/keys.py @@ -0,0 +1,46 @@ +import termios + +import gi +gi.require_version("Gtk", "3.0") + +from gi.repository import Gtk +from gi.repository import GObject + +# Control keys are intercept directly (see DESIGN.md) +CTRL = { + "c": termios.VINTR, + "z": termios.VSUSP, + "d": termios.VEOF, +} + +class Bindings(): + stylesheet = b""" + @binding-set saneterm-key-bindings { + bind "u" { "kill-after-output" () }; + bind "a" { "move-input-start" () }; + bind "e" { "move-input-end" () }; + } + + * { + -gtk-key-bindings: saneterm-key-bindings; + } + """ + + def __init__(self, widget): + self.provider = Gtk.CssProvider() + self.provider.load_from_data(self.stylesheet) + + style_ctx = widget.get_style_context() + style_ctx.add_provider(self.provider, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) + + def add_bind(self, key, signal, arg): + bindings = self.__binding_set() + # Using Gtk.BindingEntry.add_signall() would be preferable + # https://gitlab.gnome.org/GNOME/pygobject/-/issues/474 + Gtk.BindingEntry().add_signal_from_string(bindings, + F'bind "{key}" {{ "{signal}" ({arg}) }};') + + def __binding_set(self): + return Gtk.BindingSet.find("saneterm-key-bindings") + diff --git a/saneterm/terminal.py b/saneterm/terminal.py index 075eddd..60d1b24 100644 --- a/saneterm/terminal.py +++ b/saneterm/terminal.py @@ -4,7 +4,7 @@ import os import codecs import termios -import input +import keys from termview import * import gi @@ -17,13 +17,6 @@ from gi.repository import GLib NAME = "saneterm" TERM = "dumb" -# Control keys are intercept directly (see DESIGN.md) -control_keys = { - "c": termios.VINTR, - "z": termios.VSUSP, - "d": termios.VEOF, -} - class PtySource(GLib.Source): master = -1 @@ -75,8 +68,8 @@ class Terminal(Gtk.Window): self.termview.connect("new-user-input", self.user_input) self.termview.connect("termios-ctrlkey", self.termios_ctrl) - bindings = input.KeyBindings(self.termview) - for key, idx in control_keys.items(): + bindings = keys.Bindings(self.termview) + for key, idx in keys.CTRL.items(): bindings.add_bind(key, "termios-ctrlkey", idx) scroll = Gtk.ScrolledWindow().new(None, None) -- cgit 1.4.1