From a5ef6ec9105f22d14b7d7ec3b634796fc3466e93 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 28 Sep 2019 18:32:03 +0200 Subject: Add a context manager in Win for colored text --- poezio/windows/base_wins.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'poezio/windows/base_wins.py') 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 -- cgit v1.2.3