diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-09-13 21:43:58 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-09-13 21:43:58 -0400 |
commit | fc45d0b642b482f47638ca9b0f8fe69c8c9006b3 (patch) | |
tree | 72f52047dfefe2dbc12bedb824af37b316686076 /vt100.py | |
download | python-termcast-server-fc45d0b642b482f47638ca9b0f8fe69c8c9006b3.tar.gz python-termcast-server-fc45d0b642b482f47638ca9b0f8fe69c8c9006b3.zip |
initial very rough sketch
Diffstat (limited to 'vt100.py')
-rw-r--r-- | vt100.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/vt100.py b/vt100.py new file mode 100644 index 0000000..db3509c --- /dev/null +++ b/vt100.py @@ -0,0 +1,80 @@ +from ctypes import * + +libvt100 = CDLL("libvt100.so") + +class vt100_rgb_color(Union): + _fields_ = [ + ("r", c_ubyte), + ("g", c_ubyte), + ("b", c_ubyte), + ] + +class vt100_color(Structure): + _anonymous_ = ("rgb",) + _fields_ = [ + ("rgb", vt100_rgb_color), + ("type", c_ubyte), + ] + +class vt100_named_attrs(Structure): + _fields_ = [ + ("bold", c_ubyte, 1), + ("italic", c_ubyte, 1), + ("underline", c_ubyte, 1), + ("inverse", c_ubyte, 1), + ] + +class vt100_attrs(Union): + _anonymous_ = ("named",) + _fields_ = [ + ("named", vt100_named_attrs), + ("attrs", c_ubyte), + ] + +class vt100_cell_attrs(Structure): + _anonymous_ = ("cell_attrs",) + _fields_ = [ + ("fgcolor", vt100_color), + ("bgcolor", vt100_color), + ("cell_attrs", vt100_attrs), + ] + +class vt100_cell(Structure): + _fields_ = [ + ("_contents", c_char * 8), + ("len", c_size_t), + ("attrs", vt100_cell_attrs), + ("is_wide", c_ubyte, 1), + ] + + def contents(self): + return self._contents[:self.len].decode('utf-8') + +new_prototype = CFUNCTYPE(c_void_p) +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)) + +cell_at_prototype = CFUNCTYPE(POINTER(vt100_cell), c_void_p, c_int, c_int) +vt100_cell_at = cell_at_prototype(("vt100_screen_cell_at", libvt100)) + +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 __del__(self): + vt100_delete(self.vt) + + def process(self, string): + return vt100_process_string(self.vt, string, len(string)) + + def cell(self, x, y): + return vt100_cell_at(self.vt, x, y) |