From 7739fef5e8bb6672a473a7b96f24ec72589b3758 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 20 Oct 2014 00:31:02 -0400 Subject: add method to get the current cursor position --- vt100/__init__.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/vt100/__init__.py b/vt100/__init__.py index e9d3c9b..3d36d3d 100644 --- a/vt100/__init__.py +++ b/vt100/__init__.py @@ -109,10 +109,31 @@ class vt100_cell(Structure): def is_wide(self): return self._is_wide != 0 +class vt100_loc(Structure): + _fields_ = [ + ("row", c_int), + ("col", c_int), + ] + +class vt100_grid(Structure): + _fields_ = [ + ("_cur", vt100_loc), + ("_max", vt100_loc), + ("_saved", vt100_loc), + ("_selection_start", vt100_loc), + ("_selection_end", vt100_loc), + ("_scroll_top", c_int), + ("_scroll_bottom", c_int), + ("_row_count", c_int), + ("_row_capacity", c_int), + ("_row_top", c_int), + ("_rows", c_void_p), + ] + class vt100_screen(Structure): _fields_ = [ - ("_grid", c_void_p), - ("_alternate", c_void_p), + ("_grid", POINTER(vt100_grid)), + ("_alternate", POINTER(vt100_grid)), ("_title", c_char_p), ("_title_len", c_size_t), ("_icon_name", c_char_p), @@ -179,6 +200,10 @@ class vt100(object): return None return vt100_cell.from_address(vt100_raw.cell_at(self.vt, x, y)) + def cursor_pos(self): + pos = self.screen._grid.contents._cur + return pos.col, pos.row + def title(self): return self.screen._title[:self.screen._title_len].decode('utf-8') -- cgit v1.2.3-54-g00ecf