[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Moving flag and version status colors to config



commit df481c6ba04361210da781080c9c53608d762a65
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Feb 15 14:08:53 2014 -0800

    Moving flag and version status colors to config
    
    Moving some static configuration data from our source to a new attributes
    configuration.
---
 arm/config/attributes.cfg |   25 +++++++++++++++++++++++++
 arm/header_panel.py       |   37 ++++++-------------------------------
 arm/util/ui_tools.py      |    2 +-
 3 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/arm/config/attributes.cfg b/arm/config/attributes.cfg
new file mode 100644
index 0000000..340cbdc
--- /dev/null
+++ b/arm/config/attributes.cfg
@@ -0,0 +1,25 @@
+# General configuration data used by arm.
+
+attr.flag_colors Authority => white
+attr.flag_colors BadExit => red
+attr.flag_colors BadDirectory => red
+attr.flag_colors Exit => cyan
+attr.flag_colors Fast => yellow
+attr.flag_colors Guard => green
+attr.flag_colors HSDir => magenta
+attr.flag_colors Named => blue
+attr.flag_colors Stable => blue
+attr.flag_colors Running => yellow
+attr.flag_colors Unnamed => magenta
+attr.flag_colors Valid => green
+attr.flag_colors V2Dir => cyan
+attr.flag_colors V3Dir => white
+
+attr.version_status_colors new => blue
+attr.version_status_colors new in series => blue
+attr.version_status_colors obsolete => red
+attr.version_status_colors recommended => green
+attr.version_status_colors old => red
+attr.version_status_colors unrecommended => red
+attr.version_status_colors unknown => cyan
+
diff --git a/arm/header_panel.py b/arm/header_panel.py
index 6232da3..de3c5a8 100644
--- a/arm/header_panel.py
+++ b/arm/header_panel.py
@@ -36,35 +36,10 @@ from util import panel, ui_tools, tor_controller
 
 MIN_DUAL_COL_WIDTH = 141
 
-FLAG_COLORS = {
-  "Authority": "white",
-  "BadExit": "red",
-  "BadDirectory": "red",
-  "Exit": "cyan",
-  "Fast": "yellow",
-  "Guard": "green",
-  "HSDir": "magenta",
-  "Named": "blue",
-  "Stable": "blue",
-  "Running": "yellow",
-  "Unnamed": "magenta",
-  "Valid": "green",
-  "V2Dir": "cyan",
-  "V3Dir": "white",
-}
-
-VERSION_STATUS_COLORS = {
-  "new": "blue",
-  "new in series": "blue",
-  "obsolete": "red",
-  "recommended": "green",
-  "old": "red",
-  "unrecommended": "red",
-  "unknown": "cyan",
-}
-
-CONFIG = conf.config_dict("arm", {
-  "features.showFdUsage": False,
+CONFIG = conf.config_dict('arm', {
+  'attr.flag_colors': {},
+  'attr.version_status_colors': {},
+  'features.showFdUsage': False,
 })
 
 
@@ -238,7 +213,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
 
     if 7 + len(self.vals["tor/version"]) + len(self.vals["tor/versionStatus"]) <= content_space:
       if self.vals["tor/version"] != "Unknown":
-        version_color = VERSION_STATUS_COLORS[self.vals["tor/versionStatus"]] if self.vals["tor/versionStatus"] in VERSION_STATUS_COLORS else "white"
+        version_color = CONFIG['attr.version_status_colors'].get(self.vals["tor/versionStatus"], 'white')
 
         label_prefix = "Tor %s (" % self.vals["tor/version"]
         self.addstr(0, 43, label_prefix)
@@ -380,7 +355,7 @@ class HeaderPanel(panel.Panel, threading.Thread):
         if len(self.vals["tor/flags"]) > 0:
           for i in range(len(self.vals["tor/flags"])):
             flag = self.vals["tor/flags"][i]
-            flag_color = FLAG_COLORS[flag] if flag in FLAG_COLORS.keys() else "white"
+            flag_color = CONFIG['attr.flag_colors'].get(flag, 'white')
 
             self.addstr(y, x, flag, curses.A_BOLD | ui_tools.get_color(flag_color))
             x += len(flag)
diff --git a/arm/util/ui_tools.py b/arm/util/ui_tools.py
index 9e4a622..2b24b83 100644
--- a/arm/util/ui_tools.py
+++ b/arm/util/ui_tools.py
@@ -129,7 +129,7 @@ def _color_attr():
     if not CONFIG['features.colorInterface']:
       COLOR_ATTR = DEFAULT_COLOR_ATTR
     elif curses.has_colors():
-      color_attr = dict([(color, 0) for color in COLOR_LIST])
+      color_attr = dict(DEFAULT_COLOR_ATTR)
 
       for color_pair, color_name in enumerate(COLOR_LIST):
         foreground_color = COLOR_LIST[color_name]



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits