commit aa6d4e03b4a31bdfcd8f7dcc2ec1e28741bb530e Author: Damian Johnson atagar@torproject.org Date: Tue May 5 09:52:34 2015 -0700
Helper for getting curses attribute code
Just moving some repeatedly duplicated code to a helper. --- nyx/util/panel.py | 32 ++++---------------------------- nyx/util/ui_tools.py | 28 +++++++++++++++++++++------- 2 files changed, 25 insertions(+), 35 deletions(-)
diff --git a/nyx/util/panel.py b/nyx/util/panel.py index 6dc3d0e..3be145b 100644 --- a/nyx/util/panel.py +++ b/nyx/util/panel.py @@ -447,13 +447,7 @@ class Panel(object): attr - text attributes """
- format_attr = curses.A_NORMAL - - for attr in attributes: - if isinstance(attr, str): - format_attr |= ui_tools.get_color(attr) - else: - format_attr |= attr + format_attr = ui_tools.curses_format(*attributes)
if self.win and self.max_x > x and self.max_y > y: try: @@ -475,13 +469,7 @@ class Panel(object): attr - text attributes """
- format_attr = curses.A_NORMAL - - for attr in attributes: - if isinstance(attr, str): - format_attr |= ui_tools.get_color(attr) - else: - format_attr |= attr + format_attr = ui_tools.curses_format(*attributes)
if self.win and self.max_x > x and self.max_y > y: try: @@ -503,13 +491,7 @@ class Panel(object): attr - text attributes """
- format_attr = curses.A_NORMAL - - for attr in attributes: - if isinstance(attr, str): - format_attr |= ui_tools.get_color(attr) - else: - format_attr |= attr + format_attr = ui_tools.curses_format(*attributes)
if self.win and self.max_x > x and self.max_y > y: try: @@ -531,13 +513,7 @@ class Panel(object): attr - text attributes """
- format_attr = curses.A_NORMAL - - for attr in attributes: - if isinstance(attr, str): - format_attr |= ui_tools.get_color(attr) - else: - format_attr |= attr + format_attr = ui_tools.curses_format(*attributes)
# subwindows need a single character buffer (either in the x or y # direction) from actual content to prevent crash when shrank diff --git a/nyx/util/ui_tools.py b/nyx/util/ui_tools.py index 901676b..d546415 100644 --- a/nyx/util/ui_tools.py +++ b/nyx/util/ui_tools.py @@ -179,6 +179,26 @@ def get_printable(line, keep_newlines = True): return line
+def curses_format(*attributes): + """ + Provides the curses integer code for a series of attributes. + + :param list attributes: curses attributes or color names + + :returns: **int** that can be used with curses + """ + + format_attr = curses.A_NORMAL + + for attr in attributes: + if isinstance(attr, str): + format_attr |= get_color(attr) + else: + format_attr |= attr + + return format_attr + + def draw_box(panel, top, left, width, height, *attributes): """ Draws a box in the panel with the given bounds. @@ -192,13 +212,7 @@ def draw_box(panel, top, left, width, height, *attributes): attr - text attributes """
- format_attr = curses.A_NORMAL - - for attr in attributes: - if isinstance(attr, str): - format_attr |= get_color(attr) - else: - format_attr |= attr + format_attr = curses_format(*attributes)
# draws the top and bottom
tor-commits@lists.torproject.org