diff options
author | mathieui <mathieui@mathieui.net> | 2019-09-28 18:32:03 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2020-05-09 19:46:17 +0200 |
commit | a5ef6ec9105f22d14b7d7ec3b634796fc3466e93 (patch) | |
tree | c00ce4fc8599274af1d86b113b72c0ba60317c69 | |
parent | 41127e50abc3e126f953af5ad638f92d0848f9f1 (diff) | |
download | poezio-a5ef6ec9105f22d14b7d7ec3b634796fc3466e93.tar.gz poezio-a5ef6ec9105f22d14b7d7ec3b634796fc3466e93.tar.bz2 poezio-a5ef6ec9105f22d14b7d7ec3b634796fc3466e93.tar.xz poezio-a5ef6ec9105f22d14b7d7ec3b634796fc3466e93.zip |
Add a context manager in Win for colored text
-rw-r--r-- | poezio/windows/base_wins.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/poezio/windows/base_wins.py b/poezio/windows/base_wins.py index 6a689067..d6c72912 100644 --- a/poezio/windows/base_wins.py +++ b/poezio/windows/base_wins.py @@ -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 |