commit 505f4e623097d29fcc7361d375b8e11a411a4971 Author: Damian Johnson atagar@torproject.org Date: Tue Mar 15 08:43:29 2016 -0700
Curses setup() function
Moving our one-time curses setup to the nyx.curses module. --- nyx/controller.py | 18 +++--------------- nyx/curses.py | 22 ++++++++++++++++++++++ nyx/menu/menu.py | 2 +- 3 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/nyx/controller.py b/nyx/controller.py index 9a75f60..54508aa 100644 --- a/nyx/controller.py +++ b/nyx/controller.py @@ -102,7 +102,7 @@ class Controller: top to bottom on the page.
Arguments: - stdscr - curses window + stdscr - curses window """
self._screen = stdscr @@ -381,7 +381,7 @@ def start_nyx(stdscr): Main draw loop context.
Arguments: - stdscr - curses window + stdscr - curses window """
global NYX_CONTROLLER @@ -403,19 +403,7 @@ def start_nyx(stdscr): for panel_impl in control.get_daemon_panels(): panel_impl.start()
- # allows for background transparency - - try: - curses.use_default_colors() - except curses.error: - pass - - # makes the cursor invisible - - try: - curses.curs_set(0) - except curses.error: - pass + nyx.curses.setup(transparent_background = True, cursor = False)
# logs the initialization time
diff --git a/nyx/curses.py b/nyx/curses.py index 18da7f2..fa2a77c 100644 --- a/nyx/curses.py +++ b/nyx/curses.py @@ -9,6 +9,7 @@ if we want Windows support in the future too. ::
curses_attr - curses encoded text attribute + setup - configures curses settings
is_color_supported - checks if terminal supports color output get_color_override - provides color we override requests with @@ -151,6 +152,27 @@ def curses_attr(*attributes): return encoded
+def setup(transparent_background = False, cursor = True): + """ + One time setup operations for configuring curses. + + :param bool transparent_background: allows background transparency + :param bool cursor: makes cursor visible + """ + + if transparent_background: + try: + curses.use_default_colors() + except curses.error: + pass + + if not cursor: + try: + curses.curs_set(0) + except curses.error: + pass + + def is_color_supported(): """ Checks if curses currently supports rendering colors. diff --git a/nyx/menu/menu.py b/nyx/menu/menu.py index df7d499..1deab02 100644 --- a/nyx/menu/menu.py +++ b/nyx/menu/menu.py @@ -113,7 +113,7 @@ def show_menu():
draw_label = ' %s ' % top_level_item.get_label()[1] popup.addstr(0, draw_left, draw_label, BOLD, attr) - popup.addch(0, draw_left + len(draw_label), curses.ACS_VLINE) + popup.vline(0, draw_left + len(draw_label), 1)
draw_left += len(draw_label) + 1
tor-commits@lists.torproject.org