aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-14 21:57:12 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-14 21:57:12 -0400
commit033673ac065a189bc611af689c964a7f75a3a183 (patch)
tree7f4394ddb463df52d8e6966ccb58f1d3af6d8a1c
parent25378ae42097762c7b9e36b0272d8bac41baa762 (diff)
downloadpython-termcast-server-033673ac065a189bc611af689c964a7f75a3a183.tar.gz
python-termcast-server-033673ac065a189bc611af689c964a7f75a3a183.zip
set the terminal size as requested by the termcaster
-rw-r--r--termcast.py25
-rw-r--r--vt100.py10
2 files changed, 23 insertions, 12 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)
diff --git a/vt100.py b/vt100.py
index b6ec1a9..97c345d 100644
--- a/vt100.py
+++ b/vt100.py
@@ -50,12 +50,9 @@ class vt100_cell(Structure):
def contents(self):
return self._contents[:self.len].decode('utf-8')
-new_prototype = CFUNCTYPE(c_void_p)
+new_prototype = CFUNCTYPE(c_void_p, c_int, c_int)
vt100_new = new_prototype(("vt100_screen_new", libvt100))
-set_window_size_prototype = CFUNCTYPE(None, c_void_p)
-vt100_set_window_size = set_window_size_prototype(("vt100_screen_set_window_size", libvt100))
-
process_string_prototype = CFUNCTYPE(c_int, c_void_p, c_char_p, c_size_t)
vt100_process_string = process_string_prototype(("vt100_screen_process_string", libvt100))
@@ -66,9 +63,8 @@ delete_prototype = CFUNCTYPE(None, c_void_p)
vt100_delete = delete_prototype(("vt100_screen_delete", libvt100))
class vt100(object):
- def __init__(self):
- self.vt = vt100_new()
- vt100_set_window_size(self.vt)
+ def __init__(self, rows, cols):
+ self.vt = vt100_new(rows, cols)
def __del__(self):
vt100_delete(self.vt)