[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Moving glyph demo into run_tests
commit 3e5181d7817ac18d78852f5b4e77d1f8ae8ca14a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Nov 11 18:40:13 2016 -0800
Moving glyph demo into run_tests
Our demo_glyphs.py didn't work any longer because its 'import curses' clause
referenced the local copy rather than the python builtin. Regardless, this is
actually a little nicer in curses.py. To run it with the following undocumented
option...
% run_nyx --demo-glyphs
---
nyx/curses.py | 45 +++++++++++++++++++++++++++++++++++++
nyx/demo_glyphs.py | 66 ------------------------------------------------------
run_nyx | 8 ++++++-
3 files changed, 52 insertions(+), 67 deletions(-)
diff --git a/nyx/curses.py b/nyx/curses.py
index 112fd2e..f25839e 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -19,6 +19,7 @@ if we want Windows support in the future too.
screen_size - provides the dimensions of our screen
screenshot - dump of the present on-screen content
asci_to_curses - converts terminal formatting to curses
+ demo_glyphs - renders a chart showing the ACS options
halt - prevents further curses rendering during shutdown
is_color_supported - checks if terminal supports color output
@@ -529,6 +530,50 @@ def asci_to_curses(msg):
return entries
+def demo_glyphs():
+ """
+ Renders a chart of 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
+ """
+
+ def _render():
+ with raw_screen() as stdscr:
+ 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
+
+ try:
+ start(_render, transparent_background = True, cursor = False)
+ except KeyboardInterrupt:
+ pass # quit
+
+
def halt():
"""
Prevents further rendering of curses content while python's shutting down.
diff --git a/nyx/demo_glyphs.py b/nyx/demo_glyphs.py
deleted file mode 100755
index 2978873..0000000
--- a/nyx/demo_glyphs.py
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2014-2016, 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/run_nyx b/run_nyx
index 29c6be5..be9f55b 100755
--- a/run_nyx
+++ b/run_nyx
@@ -2,7 +2,13 @@
# Copyright 2009-2016, Damian Johnson and The Tor Project
# See LICENSE for licensing information
+import sys
+
import nyx
+import nyx.curses
if __name__ == '__main__':
- nyx.main()
+ if '--demo-glyphs' in sys.argv:
+ nyx.curses.demo_glyphs()
+ else:
+ nyx.main()
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits