commit bd94f0f5ef5490a48828aebfd4c11e39111daaa9 Author: Damian Johnson atagar@torproject.org Date: Wed Nov 30 10:36:15 2011 -0800
Monkey patch for ACS disabling
Making manual ACS disabling transparent to the rest of the interface by monkey patching the ord values of ACS entries to '+', '-', or '|'. This has the advantage that the rest of the arm interface doesn't need to be aware of this complication, however it doesn't address the builtin box() function usage, which still makes most dialogs render incorrectly. --- src/util/panel.py | 25 +++++-------------------- src/util/uiTools.py | 27 ++++++++++++++++++--------- 2 files changed, 23 insertions(+), 29 deletions(-)
diff --git a/src/util/panel.py b/src/util/panel.py index c0c13d8..50ae2c0 100644 --- a/src/util/panel.py +++ b/src/util/panel.py @@ -23,8 +23,7 @@ FORMAT_TAGS = {"<b>": (_noOp, curses.A_BOLD), "<h>": (_noOp, curses.A_STANDOUT)} for colorLabel in uiTools.COLOR_LIST: FORMAT_TAGS["<%s>" % colorLabel] = (uiTools.getColor, colorLabel)
-CONFIG = {"features.acsSupport": True, - "log.panelRecreated": log.DEBUG} +CONFIG = {"log.panelRecreated": log.DEBUG}
# prevents curses redraws if set HALT_ACTIVITY = False @@ -426,11 +425,7 @@ class Panel(): if self.win and self.maxX > x and self.maxY > y: try: drawLength = min(length, self.maxX - x) - - if CONFIG["features.acsSupport"]: - self.win.hline(y, x, curses.ACS_HLINE | attr, drawLength) - else: - self.addstr(y, x, "-" * drawLength, attr) + self.win.hline(y, x, curses.ACS_HLINE | attr, drawLength) except: # in edge cases drawing could cause a _curses.error pass @@ -450,12 +445,7 @@ class Panel(): if self.win and self.maxX > x and self.maxY > y: try: drawLength = min(length, self.maxY - y) - - if CONFIG["features.acsSupport"]: - self.win.vline(y, x, curses.ACS_VLINE | attr, drawLength) - else: - for i in range(drawLength): - self.addch(y + i, x, "|", attr) + self.win.vline(y, x, curses.ACS_VLINE | attr, drawLength) except: # in edge cases drawing could cause a _curses.error pass @@ -696,13 +686,8 @@ class Panel():
# draws box around the scroll bar self.vline(drawTop, drawLeft + 1, drawBottom - 1) - - if CONFIG["features.acsSupport"]: - self.addch(drawBottom, drawLeft + 1, curses.ACS_LRCORNER) - self.addch(drawBottom, drawLeft, curses.ACS_HLINE) - else: - self.addch(drawBottom, drawLeft + 1, "+") - self.addch(drawBottom, drawLeft, "-") + self.addch(drawBottom, drawLeft + 1, curses.ACS_LRCORNER) + self.addch(drawBottom, drawLeft, curses.ACS_HLINE)
def _resetSubwindow(self): """ diff --git a/src/util/uiTools.py b/src/util/uiTools.py index 51f5fee..bc1fefe 100644 --- a/src/util/uiTools.py +++ b/src/util/uiTools.py @@ -338,15 +338,9 @@ def drawBox(panel, top, left, width, height, attr=curses.A_NORMAL): panel.vline(top + 1, left + width - 1, height - 2, attr)
# draws the corners - if CONFIG["features.acsSupport"]: - panel.addch(top, left, curses.ACS_ULCORNER, attr) - panel.addch(top, left + width - 1, curses.ACS_URCORNER, attr) - panel.addch(top + height - 1, left, curses.ACS_LLCORNER, attr) - else: - panel.addch(top, left, "+", attr) - panel.addch(top, left + width - 1, "+", attr) - panel.addch(top + height - 1, left, "+", attr) - panel.addch(top + height - 1, left + width - 1, "+", attr) + panel.addch(top, left, curses.ACS_ULCORNER, attr) + panel.addch(top, left + width - 1, curses.ACS_URCORNER, attr) + panel.addch(top + height - 1, left, curses.ACS_LLCORNER, attr)
def isSelectionKey(key): """ @@ -714,6 +708,21 @@ def _initColors():
global COLOR_ATTR_INITIALIZED, COLOR_IS_SUPPORTED if not COLOR_ATTR_INITIALIZED: + # hack to replace all ACS characters with '+' if ACS support has been + # manually disabled + if not CONFIG["features.acsSupport"]: + for item in curses.__dict__: + if item.startswith("ACS_"): + curses.__dict__[item] = ord('+') + + # replace a few common border pipes that are better rendered as '|' or + # '-' instead + + curses.ACS_SBSB = ord('|') + curses.ACS_VLINE = ord('|') + curses.ACS_BSBS = ord('-') + curses.ACS_HLINE = ord('-') + COLOR_ATTR_INITIALIZED = True COLOR_IS_SUPPORTED = False if not CONFIG["features.colorInterface"]: return
tor-commits@lists.torproject.org