Add a context manager in Win for colored text

This commit is contained in:
mathieui 2019-09-28 18:32:03 +02:00
parent 41127e50ab
commit a5ef6ec910

View file

@ -77,6 +77,19 @@ class Win:
# of the screen.
pass
@contextmanager
def colored_text(self, color: Optional[Tuple]=None, attr: Optional[int]=None):
"""Context manager which sets up an attr/color when inside"""
if attr is None:
if color is not None:
attr = to_curses_attr(color)
else:
yield None
return
self._win.attron(attr)
yield None
self._win.attroff(attr)
def addstr(self, *args) -> None:
"""
Safe call to addstr