[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/release] Adding an option to override interface colors
commit d3a1f351009103169e63e85ab366ca4167cb2add
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Jun 11 12:42:49 2011 -0700
Adding an option to override interface colors
This causes all color requests for the interface to be replaced with the
overridden color (ie, everything except white content is replaced). This is a
neat looking effect and will be added as an option to the menu (it's currently
a config option).
---
armrc.sample | 5 +++++
src/util/uiTools.py | 38 +++++++++++++++++++++++++++++++++++++-
2 files changed, 42 insertions(+), 1 deletions(-)
diff --git a/armrc.sample b/armrc.sample
index ecfe45a..1eafe77 100644
--- a/armrc.sample
+++ b/armrc.sample
@@ -19,6 +19,11 @@ queries.useProc true
# Renders the interface with color if set and the terminal supports it
features.colorInterface true
+# Replaces all colored content (ie, anything that isn't white) with this
+# color. Valid options are:
+# none, red, green, yellow, blue, cyan, magenta, black, white
+features.colorOverride none
+
# Includes unicode characters in the interface.
features.printUnicode true
diff --git a/src/util/uiTools.py b/src/util/uiTools.py
index 0ff680e..5999c64 100644
--- a/src/util/uiTools.py
+++ b/src/util/uiTools.py
@@ -37,7 +37,8 @@ Ending = enum.Enum("ELLIPSE", "HYPHEN")
SCROLL_KEYS = (curses.KEY_UP, curses.KEY_DOWN, curses.KEY_PPAGE, curses.KEY_NPAGE, curses.KEY_HOME, curses.KEY_END)
CONFIG = {"features.colorInterface": True,
"features.printUnicode": True,
- "log.cursesColorSupport": log.INFO}
+ "log.cursesColorSupport": log.INFO,
+ "log.configEntryTypeError": log.NOTICE}
# Flag indicating if unicode is supported by curses. If None then this has yet
# to be determined.
@@ -45,6 +46,14 @@ IS_UNICODE_SUPPORTED = None
def loadConfig(config):
config.update(CONFIG)
+
+ CONFIG["features.colorOverride"] = "none"
+ colorOverride = config.get("features.colorOverride", "none")
+
+ if colorOverride != "none":
+ try: setColorOverride(colorOverride)
+ except ValueError, exc:
+ log.log(CONFIG["log.configEntryTypeError"], exc)
def demoGlyphs():
"""
@@ -143,9 +152,36 @@ def getColor(color):
color - name of the foreground color to be returned
"""
+ colorOverride = getColorOverride()
+ if colorOverride: color = colorOverride
if not COLOR_ATTR_INITIALIZED: _initColors()
return COLOR_ATTR[color]
+def setColorOverride(color = None):
+ """
+ Overwrites all requests for color with the given color instead. This raises
+ a ValueError if the color is invalid.
+
+ Arguments:
+ color - name of the color to overwrite requests with, None to use normal
+ coloring
+ """
+
+ if color == None:
+ CONFIG["features.colorOverride"] = "none"
+ elif color in COLOR_LIST.keys():
+ CONFIG["features.colorOverride"] = color
+ else: raise ValueError("\"%s\" isn't a valid color" % color)
+
+def getColorOverride():
+ """
+ Provides the override color used by the interface, None if it isn't set.
+ """
+
+ colorOverride = CONFIG.get("features.colorOverride", "none")
+ if colorOverride == "none": return None
+ else: return colorOverride
+
def cropStr(msg, size, minWordLen = 4, minCrop = 0, endType = Ending.ELLIPSE, getRemainder = False):
"""
Provides the msg constrained to the given length, truncating on word breaks.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits