From f44c44324c24aa667bfd56bb7b9ee2e96ac93bd4 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 23 Sep 2014 13:28:51 -0400 Subject: a bit better clear handling really need to get the rendering stuff working, but this will help for now --- termcast.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/termcast.py b/termcast.py index ce97cd7..e4eed6d 100644 --- a/termcast.py +++ b/termcast.py @@ -7,6 +7,17 @@ import vt100 auth_re = re.compile(b'^hello ([^ ]+) ([^ ]+)$') extra_data_re = re.compile(b'\033\]499;([^\007]*)\007') +clear_patterns = [ + b"\033[H\033[J", + b"\033[H\033[2J", + b"\033[2J\033[H", + # this one is from tmux - can't possibly imagine why it would choose to do + # things this way, but i'm sure there's some kind of reason + # it's not perfect (it's not always followed by a \e[H, sometimes it just + # moves the cursor to wherever else directly), but it helps a bit + lambda handler: b"\033[H\033[K\r\n\033[K" + b"".join([b"\033[1B\033[K" for i in range(handler.rows - 2)]) + b"\033[H", +] + class Handler(object): def __init__(self, rows, cols): self.created_at = time.time() @@ -41,13 +52,13 @@ class Handler(object): self.cols = extra_data["geometry"][0] self.vt.set_window_size(self.rows, self.cols) - clear = self.buf.rfind(b"\033[H\033[J") - if clear != -1: - self.buf = self.buf[clear + 6:] - - clear = self.buf.rfind(b"\033[2J\033[H") - if clear != -1: - self.buf = self.buf[clear + 7:] + for pattern in clear_patterns: + if type(pattern) == type(lambda x: x): + pattern = pattern(self) + clear = self.buf.rfind(pattern) + if clear != -1: + print("found a clear") + self.buf = self.buf[clear + len(pattern):] self.idle_since = time.time() -- cgit v1.2.3