about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2021-05-16 01:55:00 +0200
committerSören Tempel <soeren+git@soeren-tempel.net>2021-05-16 01:55:00 +0200
commitcb70a6351e2476049f26d2b7de85d33dc3177101 (patch)
tree9c167bfcec41c78694a481d2b0b6ead27f65c0a5
parentd397ddfd64d0cd49342166b366d4dcf3c3202e19 (diff)
Start working on custom keybindings
-rw-r--r--src/input.py24
-rw-r--r--src/terminal.py5
2 files changed, 29 insertions, 0 deletions
diff --git a/src/input.py b/src/input.py
new file mode 100644
index 0000000..c6822bd
--- /dev/null
+++ b/src/input.py
@@ -0,0 +1,24 @@
+import gi
+gi.require_version("Gtk", "3.0")
+
+from gi.repository import Gtk
+
+class KeyBindings():
+    stylesheet = b"""
+        @binding-set saneterm-key-bindings {
+            bind "<ctrl>h" { "delete-from-cursor" (chars, -1) };
+        }
+
+        * {
+             -gtk-key-bindings: saneterm-key-bindings;
+        }
+    """
+
+    def __init__(self):
+        self.provider = Gtk.CssProvider()
+        self.provider.load_from_data(self.stylesheet)
+
+    def apply(self, widget):
+        style_ctx = widget.get_style_context()
+        style_ctx.add_provider(self.provider,
+                Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
diff --git a/src/terminal.py b/src/terminal.py
index 6c58dee..52435a6 100644
--- a/src/terminal.py
+++ b/src/terminal.py
@@ -3,6 +3,8 @@ import pty
 import os
 import codecs
 
+import input
+
 import gi
 gi.require_version("Gtk", "3.0")
 
@@ -66,6 +68,9 @@ class Terminal(Gtk.Window):
         # Block-wise reading from the PTY requires an incremental decoder.
         self.decoder = codecs.getincrementaldecoder('UTF-8')()
 
+        bindings = input.KeyBindings()
+        bindings.apply(self.textview)
+
         self.add(self.textview)
 
     def handle_pty(self, master):