Add a context manager in Win for colored text
This commit is contained in:
parent
41127e50ab
commit
a5ef6ec910
1 changed files with 13 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue