aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--termcast.py22
1 files changed, 9 insertions, 13 deletions
diff --git a/termcast.py b/termcast.py
index 23c4b62..76ee3f3 100644
--- a/termcast.py
+++ b/termcast.py
@@ -14,37 +14,33 @@ class Handler(object):
self.rows = rows
self.cols = cols
self.buf = b''
+ self.prev_read = b''
self.vt = vt100.vt100(rows, cols)
def process(self, data):
- # XXX this will break if the data is split between reads, but i don't
- # know if there's anything we can do about this, because we'll have
- # already processed the beginning of it if that happens. we might need
- # some better framing which allows us to detect the start of an out of
- # band section even when the end hasn't been received yet
+ to_process = self.prev_read + data
+ processed = self.vt.process(to_process)
+ self.prev_read = to_process[processed:]
+
+ self.buf += data
+
extra_data = {}
while True:
- m = extra_data_re.search(data)
+ m = extra_data_re.search(self.buf)
if m is None:
break
extra_data_json = m.group(1)
extra_data = json.loads(extra_data_json.decode('utf-8'))
- data = data[:m.start(0)] + data[m.end(0):]
+ self.buf = self.buf[:m.start(0)] + self.buf[m.end(0):]
if "geometry" in extra_data:
self.rows = extra_data["geometry"][1]
self.cols = extra_data["geometry"][0]
self.vt.set_window_size(self.rows, self.cols)
- self.buf += data
-
clear = self.buf.rfind(b"\033[2J")
if clear != -1:
self.buf = self.buf[clear + 4:]
- # XXX need to check how much was actually processed here, to avoid
- # breaking when escape sequences or utf-8 sequences are split across
- # reads
- self.vt.process(data)
self.idle_since = time.time()
def get_term(self):