aboutsummaryrefslogtreecommitdiffstats
path: root/vt100
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-16 20:21:58 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-16 20:21:58 -0400
commite64bcd5a81149c7ad5b5c39b7c1140d5f47ccc6b (patch)
tree5cd32247f34e7ed1eb05ef91e1c92c526b4ea139 /vt100
parenta80e1a9a8863235102faf5250d3021065d1eea1f (diff)
downloadlibvt100-python-e64bcd5a81149c7ad5b5c39b7c1140d5f47ccc6b.tar.gz
libvt100-python-e64bcd5a81149c7ad5b5c39b7c1140d5f47ccc6b.zip
reimplement the api
Diffstat (limited to 'vt100')
-rw-r--r--vt100/__init__.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/vt100/__init__.py b/vt100/__init__.py
new file mode 100644
index 0000000..4e1a192
--- /dev/null
+++ b/vt100/__init__.py
@@ -0,0 +1,78 @@
+from ctypes import *
+
+import vt100_raw
+
+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')
+
+# XXX process/cell need mutexes
+class vt100(object):
+ def __init__(self, rows, cols):
+ self.vt = vt100_raw.new(rows, cols)
+
+ def __del__(self):
+ vt100_raw.delete(self.vt)
+
+ def set_window_size(self, rows, cols):
+ vt100_raw.set_window_size(self.vt, rows, cols)
+
+ def process(self, string):
+ return vt100_raw.process_string(self.vt, string)
+
+ def get_string_formatted(self, row_start, col_start, row_end, col_end):
+ return vt100_raw.get_string_formatted(
+ self.vt, row_start, col_start, row_end, col_end
+ )
+
+ def get_string_plaintext(self, row_start, col_start, row_end, col_end):
+ return vt100_raw.get_string_plaintext(
+ self.vt, row_start, col_start, row_end, col_end
+ )
+
+ def cell(self, x, y):
+ return cast(vt100_raw.cell_at(self.vt, x, y), vt100_cell)