commit 7b93874508050223d5ed36b67b889f1cbdfaa432 Author: Damian Johnson atagar@torproject.org Date: Sat Jan 25 13:59:25 2014 -0800
Moving glyph demoing to its own executable
Our curses glyph demo is a handly tool for curses development, but there's no reason for it to be part of our ui_tools. It's a script to demo curses' capabilities and only ever meant to be a reference during development. --- arm/demo_glyphs.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++ arm/util/ui_tools.py | 69 +++----------------------------------------------- 2 files changed, 69 insertions(+), 66 deletions(-)
diff --git a/arm/demo_glyphs.py b/arm/demo_glyphs.py new file mode 100755 index 0000000..7781139 --- /dev/null +++ b/arm/demo_glyphs.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# Copyright 2014, Damian Johnson and The Tor Project +# See LICENSE for licensing information + +""" +Displays all ACS options with their corresponding representation. These are +undocumented in the pydocs. For more information see the following man page: + +http://www.mkssoftware.com/docs/man5/terminfo.5.asp +""" + +import curses + + +def main(): + try: + curses.wrapper(_show_glyphs) + except KeyboardInterrupt: + pass # quit + + +def _show_glyphs(stdscr): + """ + Renders a chart with the ACS glyphs. + """ + + try: + curses.use_default_colors() # allow semi-transparent backgrounds + except curses.error: + pass + + try: + curses.curs_set(0) # attempt to make the cursor invisible + except curses.error: + pass + + height, width = stdscr.getmaxyx() + columns = width / 30 + + if columns == 0: + return # not wide enough to show anything + + # mapping of keycodes to their ACS option names (for instance, ACS_LTEE) + + acs_options = dict((v, k) for (k, v) in curses.__dict__.items() if k.startswith('ACS_')) + + stdscr.addstr(0, 0, 'Curses Glyphs:', curses.A_STANDOUT) + x, y = 0, 2 + + for keycode in sorted(acs_options.keys()): + stdscr.addstr(y, x * 30, '%s (%i)' % (acs_options[keycode], keycode)) + stdscr.addch(y, (x * 30) + 25, keycode) + + x += 1 + + if x >= columns: + x, y = 0, y + 1 + + if y >= height: + break + + stdscr.getch() # quit on keyboard input + + +if __name__ == '__main__': + main() diff --git a/arm/util/ui_tools.py b/arm/util/ui_tools.py index 7a1a601..1d90001 100644 --- a/arm/util/ui_tools.py +++ b/arm/util/ui_tools.py @@ -13,6 +13,7 @@ from curses.ascii import isprint from stem.util import conf, enum, log, system
# colors curses can handle + COLOR_LIST = { "red": curses.COLOR_RED, "green": curses.COLOR_GREEN, @@ -25,10 +26,12 @@ COLOR_LIST = { }
# boolean for if we have color support enabled, None not yet determined + COLOR_IS_SUPPORTED = None
# mappings for get_color() - this uses the default terminal color scheme if # color support is unavailable + COLOR_ATTR_INITIALIZED = False COLOR_ATTR = dict([(color, 0) for color in COLOR_LIST])
@@ -51,72 +54,6 @@ CONFIG = conf.config_dict("arm", { }, conf_handler)
-def demo_glyphs(): - """ - Displays all ACS options with their corresponding representation. These are - undocumented in the pydocs. For more information see the following man page: - http://www.mkssoftware.com/docs/man5/terminfo.5.asp - """ - - try: - curses.wrapper(_show_glyphs) - except KeyboardInterrupt: - pass # quit - - -def _show_glyphs(stdscr): - """ - Renders a chart with the ACS glyphs. - """ - - # allows things like semi-transparent backgrounds - - try: - curses.use_default_colors() - except curses.error: - pass - - # attempts to make the cursor invisible - - try: - curses.curs_set(0) - except curses.error: - pass - - acs_options = [item for item in curses.__dict__.items() if item[0].startswith("ACS_")] - acs_options.sort(key=lambda i: (i[1])) # order by character codes - - # displays a chart with all the glyphs and their representations - - height, width = stdscr.getmaxyx() - - if width < 30: - return # not enough room to show a column - - columns = width / 30 - - # display title - - stdscr.addstr(0, 0, "Curses Glyphs:", curses.A_STANDOUT) - - x, y = 0, 1 - - while acs_options: - name, keycode = acs_options.pop(0) - stdscr.addstr(y, x * 30, "%s (%i)" % (name, keycode)) - stdscr.addch(y, (x * 30) + 25, keycode) - - x += 1 - - if x >= columns: - x, y = 0, y + 1 - - if y >= height: - break - - stdscr.getch() # quit on keyboard input - - def get_printable(line, keep_newlines = True): """ Provides the line back with non-printable characters stripped.