From 204be3f70fcebc81a3ca78b8e3f08a3ff192a46a Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 28 Jun 2016 10:39:56 +0200 Subject: Make tcvt aware of the OSC sequences Ansi is vague about the meaning of the OSC sequences (i.e., the control sequences starting with ]): the interpretation is up to the operating system. Nevertheless, some programs send these sequences, most prominently the one to set the terminal title (OSC 0;). So make tcvt aware of those sequences and pass them through. Signed-off-by: Helmut Grohne --- tcvt.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tcvt.py') diff --git a/tcvt.py b/tcvt.py index 55084b8..0e1a528 100755 --- a/tcvt.py +++ b/tcvt.py @@ -562,6 +562,8 @@ class Terminal: def feed_esc(self, char): if char == ord(b'['): self.mode = (self.feed_esc_opbr,) + elif char == ord(b']'): + self.mode = (self.feed_esc_clbr, bytearray()) else: raise ValueError("feed esc %r" % char) @@ -660,6 +662,28 @@ class Terminal: else: raise ValueError("feed esc [ %r %r" % (prev, char)) + def feed_esc_clbr(self, char, prev): + self.feed_reset() + if char == 7: + # Bell character, end of control sequence; pass it through + # if one of those that do not interfere with the other curses. + if not prev.startswith((b"0;", b"1;", b"2;")): + raise ValueError("dropped osc sequence: esc ] %r bel" + % (prev,)) + self.refresh() + if sys.version_info.major == 2: + stdout = sys.stdout + else: + stdout = sys.stdout.buffer + stdout.write(bytearray(b"\x1b]") + prev + bytearray(b"\x07")) + stdout.flush() + + elif 8 <= char <= 13 or 32 <= char <= 126: + self.mode = (self.feed_esc_clbr, prev + bytearray((char,))) + else: + raise ValueError("feed esc ] %r %r" % (prev, char)) + + symbolic_keymapping = { ord(b"\n"): "cr", curses.KEY_LEFT: "kcub1", -- cgit v1.2.3