summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Aehlig <aehlig@linta.de>2016-06-28 10:39:56 +0200
committerHelmut Grohne <helmut@subdivi.de>2016-12-12 20:27:24 +0100
commit204be3f70fcebc81a3ca78b8e3f08a3ff192a46a (patch)
treee44c4c3367978ddbac4d48439bbd0c513708af42
parent82c24e26035ac7539fb4263ae7020ff6429c61b8 (diff)
downloadtcvt-204be3f70fcebc81a3ca78b8e3f08a3ff192a46a.tar.gz
Make tcvt aware of the OSC sequences
Ansi is vague about the meaning of the OSC sequences (i.e., the control sequences starting with <esc> ]): 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 <helmut@subdivi.de>
-rwxr-xr-xtcvt.py24
1 files changed, 24 insertions, 0 deletions
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",