Add line buffering options
This commit is contained in:
parent
5f3fdf2600
commit
c26b6eac57
@ -131,6 +131,8 @@ class ClearType(enum.IntEnum):
|
|||||||
RIGHT = 5
|
RIGHT = 5
|
||||||
|
|
||||||
class BTUI:
|
class BTUI:
|
||||||
|
_autoflush = True
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def attributes(self, *attrs):
|
def attributes(self, *attrs):
|
||||||
self.set_attributes(*attrs)
|
self.set_attributes(*attrs)
|
||||||
@ -148,7 +150,8 @@ class BTUI:
|
|||||||
if isinstance(clear_type, str):
|
if isinstance(clear_type, str):
|
||||||
clear_type = ClearType[clear_type.upper()]
|
clear_type = ClearType[clear_type.upper()]
|
||||||
libbtui.btui_clear(self._btui, clear_type)
|
libbtui.btui_clear(self._btui, clear_type)
|
||||||
libbtui.btui_flush(self._btui)
|
if self._autoflush:
|
||||||
|
libbtui.btui_flush(self._btui)
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
libbtui.btui_disable(self._btui)
|
libbtui.btui_disable(self._btui)
|
||||||
@ -183,12 +186,21 @@ class BTUI:
|
|||||||
def fill_box(self, x, y, w, h):
|
def fill_box(self, x, y, w, h):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
libbtui.btui_fill_box(self._btui, int(x), int(y), int(w), int(h))
|
libbtui.btui_fill_box(self._btui, int(x), int(y), int(w), int(h))
|
||||||
libbtui.btui_flush(self._btui)
|
if self._autoflush:
|
||||||
|
libbtui.btui_flush(self._btui)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
libbtui.btui_flush(self._btui)
|
libbtui.btui_flush(self._btui)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def buffered(self):
|
||||||
|
assert self._btui
|
||||||
|
self._autoflush = False
|
||||||
|
yield
|
||||||
|
self._autoflush = True
|
||||||
|
self.flush()
|
||||||
|
|
||||||
def getkey(self, timeout=None):
|
def getkey(self, timeout=None):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
timeout = -1 if timeout is None else int(timeout)
|
timeout = -1 if timeout is None else int(timeout)
|
||||||
@ -210,29 +222,34 @@ class BTUI:
|
|||||||
def move(self, x, y):
|
def move(self, x, y):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
libbtui.btui_move_cursor(self._btui, int(x), int(y))
|
libbtui.btui_move_cursor(self._btui, int(x), int(y))
|
||||||
libbtui.btui_flush(self._btui)
|
if self._autoflush:
|
||||||
|
libbtui.btui_flush(self._btui)
|
||||||
|
|
||||||
def set_cursor(self, cursor_type=CursorType.DEFAULT):
|
def set_cursor(self, cursor_type=CursorType.DEFAULT):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
if isinstance(cursor_type, str):
|
if isinstance(cursor_type, str):
|
||||||
cursor_type = CursorType[cursor_type.upper()]
|
cursor_type = CursorType[cursor_type.upper()]
|
||||||
libbtui.btui_set_cursor(self._btui, cursor_type)
|
libbtui.btui_set_cursor(self._btui, cursor_type)
|
||||||
libbtui.btui_flush(self._btui)
|
if self._autoflush:
|
||||||
|
libbtui.btui_flush(self._btui)
|
||||||
|
|
||||||
def hide_cursor(self):
|
def hide_cursor(self):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
libbtui.btui_hide_cursor(self._btui)
|
libbtui.btui_hide_cursor(self._btui)
|
||||||
libbtui.btui_flush(self._btui)
|
if self._autoflush:
|
||||||
|
libbtui.btui_flush(self._btui)
|
||||||
|
|
||||||
def show_cursor(self):
|
def show_cursor(self):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
libbtui.btui_show_cursor(self._btui)
|
libbtui.btui_show_cursor(self._btui)
|
||||||
libbtui.btui_flush(self._btui)
|
if self._autoflush:
|
||||||
|
libbtui.btui_flush(self._btui)
|
||||||
|
|
||||||
def outline_box(self, x, y, w, h):
|
def outline_box(self, x, y, w, h):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
libbtui.btui_draw_linebox(self._btui, int(x), int(y), int(w), int(h))
|
libbtui.btui_draw_linebox(self._btui, int(x), int(y), int(w), int(h))
|
||||||
libbtui.btui_flush(self._btui)
|
if self._autoflush:
|
||||||
|
libbtui.btui_flush(self._btui)
|
||||||
|
|
||||||
def scroll(self, firstline, lastline=None, amount=None):
|
def scroll(self, firstline, lastline=None, amount=None):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
@ -240,7 +257,8 @@ class BTUI:
|
|||||||
amount = firstline
|
amount = firstline
|
||||||
firstline, lastline = 0, self.height-1
|
firstline, lastline = 0, self.height-1
|
||||||
libbtui.btui_scroll(self._btui, firstline, lastline, amount)
|
libbtui.btui_scroll(self._btui, firstline, lastline, amount)
|
||||||
libbtui.btui_flush(self._btui)
|
if self._autoflush:
|
||||||
|
libbtui.btui_flush(self._btui)
|
||||||
|
|
||||||
def set_attributes(self, *attrs):
|
def set_attributes(self, *attrs):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
@ -285,7 +303,8 @@ class BTUI:
|
|||||||
def write_bytes(self, b):
|
def write_bytes(self, b):
|
||||||
assert self._btui
|
assert self._btui
|
||||||
libbtui.btui_puts(self._btui, b)
|
libbtui.btui_puts(self._btui, b)
|
||||||
libbtui.btui_flush(self._btui)
|
if self._autoflush:
|
||||||
|
libbtui.btui_flush(self._btui)
|
||||||
|
|
||||||
def delay(fn):
|
def delay(fn):
|
||||||
@functools.wraps(fn)
|
@functools.wraps(fn)
|
||||||
|
@ -181,6 +181,8 @@ class BTUI:
|
|||||||
def attributes(self, *attrs):
|
def attributes(self, *attrs):
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def bg(self, r, g, b): # R,G,B values are [0.0, 1.0]
|
def bg(self, r, g, b): # R,G,B values are [0.0, 1.0]
|
||||||
|
@contextmanager
|
||||||
|
def buffered(self):
|
||||||
def clear(self, mode='screen'):
|
def clear(self, mode='screen'):
|
||||||
def disable(self):
|
def disable(self):
|
||||||
@contextmanager
|
@contextmanager
|
||||||
|
Loading…
Reference in New Issue
Block a user