diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-09-14 21:57:12 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-09-14 21:57:12 -0400 |
commit | 033673ac065a189bc611af689c964a7f75a3a183 (patch) | |
tree | 7f4394ddb463df52d8e6966ccb58f1d3af6d8a1c /termcast.py | |
parent | 25378ae42097762c7b9e36b0272d8bac41baa762 (diff) | |
download | python-termcast-server-033673ac065a189bc611af689c964a7f75a3a183.tar.gz python-termcast-server-033673ac065a189bc611af689c964a7f75a3a183.zip |
set the terminal size as requested by the termcaster
Diffstat (limited to 'termcast.py')
-rw-r--r-- | termcast.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/termcast.py b/termcast.py index f94f5c7..aea056c 100644 --- a/termcast.py +++ b/termcast.py @@ -1,11 +1,14 @@ +import json import re import vt100 class Handler(object): - def __init__(self): + def __init__(self, rows, cols): + self.rows = rows + self.cols = cols self.buf = b'' - self.vt = vt100.vt100() + self.vt = vt100.vt100(rows, cols) def process(self, data): self.buf += data @@ -13,8 +16,8 @@ class Handler(object): def get_term(self): term = '' - for i in range(0, 24): - for j in range(0, 80): + for i in range(0, self.rows): + for j in range(0, self.cols): term += self.vt.cell(i, j).contents() term += "\n" @@ -44,9 +47,21 @@ class Connection(object): return print(b"got auth: " + auth) - self.handler = Handler() self.client.send(b"hello, " + m.group(1) + b"\n") + extra_data = {} + extra_data_re = re.compile(b'^\033\[H\000([^\377]*)\377\033\[H\033\[2J(.*)$') + m = extra_data_re.match(buf) + if m is not None: + extra_data_json = m.group(1) + extra_data = json.loads(extra_data_json.decode('utf-8')) + buf = m.group(2) + + if "geometry" in extra_data: + self.handler = Handler(extra_data["geometry"][1], extra_data["geometry"][0]) + else: + self.handler = Handler(24, 80) + self.handler.process(buf) while True: buf = self.client.recv(1024) |