From 1047afa31e415d2ccc59af169e0bbe3175a708d3 Mon Sep 17 00:00:00 2001 From: Sören Tempel Date: Sun, 16 May 2021 05:48:39 +0200 Subject: Add support for ctrl+c to interrupt the program via sigint --- saneterm/input.py | 1 + saneterm/terminal.py | 7 +++++++ saneterm/termview.py | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/saneterm/input.py b/saneterm/input.py index fdebb7c..7ca3e54 100644 --- a/saneterm/input.py +++ b/saneterm/input.py @@ -10,6 +10,7 @@ class KeyBindings(): bind "u" { "kill-after-output" () }; bind "a" { "move-input-start" () }; bind "e" { "move-input-end" () }; + bind "c" { "interrupt" () }; } * { diff --git a/saneterm/terminal.py b/saneterm/terminal.py index 66cdae7..7879a86 100644 --- a/saneterm/terminal.py +++ b/saneterm/terminal.py @@ -2,6 +2,7 @@ import sys import pty import os import codecs +import termios import input from termview import * @@ -62,6 +63,8 @@ class Terminal(Gtk.Window): bindings.apply(self.termview) self.termview.connect("new-user-input", self.user_input) + self.termview.connect("interrupt", self.interrupt) + self.add(self.termview) def handle_pty(self, master): @@ -75,3 +78,7 @@ class Terminal(Gtk.Window): def user_input(self, termview, line): os.write(self.pty.master, line.encode("UTF-8")) + + def interrupt(self, termview): + cc = termios.tcgetattr(self.pty.master)[-1] + os.write(self.pty.master, cc[termios.VINTR]) diff --git a/saneterm/termview.py b/saneterm/termview.py index b587456..789f25c 100644 --- a/saneterm/termview.py +++ b/saneterm/termview.py @@ -37,6 +37,7 @@ class TermView(Gtk.TextView): "kill-after-output": self.__kill_after_output, "move-input-start": self.__move_input_start, "move-input-end": self.__move_input_end, + "interrupt": None } for signal in signals.items(): @@ -45,7 +46,8 @@ class TermView(Gtk.TextView): GObject.SIGNAL_ACTION, GObject.TYPE_NONE, ()) - self.connect(name, func) + if not func is None: + self.connect(name, func) GObject.signal_new("new-user-input", self, GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, -- cgit 1.4.1