[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Drop nyx.curses.raw_screen()
commit fea209127484d9b304b908a4711c9528b1d065bc
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Dec 2 10:16:33 2016 -0800
Drop nyx.curses.raw_screen()
Direct raw curses usage was always intended to be temporary while writing the
nyx.curses module. Now that it's done we can drop its final usage. I'd like to
do away with this refresh() method too but still gotta check if it's necessary.
---
nyx/__init__.py | 6 ++--
nyx/curses.py | 83 +++++++++++++++++++++++-------------------------------
nyx/panel/graph.py | 4 +--
3 files changed, 38 insertions(+), 55 deletions(-)
diff --git a/nyx/__init__.py b/nyx/__init__.py
index b9624a7..105a72a 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -128,8 +128,7 @@ def draw_loop():
while not interface._quit:
interface.redraw()
- with nyx.curses.raw_screen() as stdscr:
- stdscr.refresh()
+ nyx.curses.refresh() # TODO: is this necessary?
if next_key:
key, next_key = next_key, None
@@ -446,8 +445,7 @@ class Interface(object):
# https://trac.torproject.org/projects/tor/ticket/2830#comment:9
if force:
- with nyx.curses.raw_screen() as stdscr:
- stdscr.clear()
+ nyx.curses.clear()
occupied = 0
diff --git a/nyx/curses.py b/nyx/curses.py
index feb1ef7..6d61867 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -12,10 +12,11 @@ if we want Windows support in the future too.
::
start - initializes curses with the given function
- raw_screen - provides direct access to the curses screen
key_input - get keypress by user
str_input - text field where user can input a string
curses_attr - curses encoded text attribute
+ refresh - flushes content to the screen
+ clear - wipes all content from the screen
screen_size - provides the dimensions of our screen
screenshot - dump of the present on-screen content
asci_to_curses - converts terminal formatting to curses
@@ -216,35 +217,6 @@ def start(function, acs_support = True, transparent_background = False, cursor =
curses.wrapper(_wrapper)
-def raw_screen():
- """
- Provides the curses screen. This can only be called after
- :func:`~nyx.curses.start`, and is used as follows...
-
- ::
-
- with nyx.curses.raw_screen() as stdscr:
- ... work with curses...
-
- In the future this will never be called directly. This is just an
- intermediate function as we migrate.
- """
-
- class _Wrapper(object):
- def __enter__(self):
- # TODO: We should be wrapping this with CURSES_LOCK.acquire/release(),
- # but doing so seems to be causing frequent terminal gliches when
- # shutting down. Strange since this should be strictly safer. Oh well -
- # something to dig into later.
-
- return CURSES_SCREEN
-
- def __exit__(self, exit_type, value, traceback):
- pass
-
- return _Wrapper()
-
-
def key_input(input_timeout = None):
"""
Gets a key press from the user.
@@ -460,6 +432,22 @@ def curses_attr(*attributes):
return encoded
+def refresh():
+ """
+ Ensure content is flushed to the screen.
+ """
+
+ CURSES_SCREEN.refresh()
+
+
+def clear():
+ """
+ Clears all content from the screen.
+ """
+
+ CURSES_SCREEN.clear()
+
+
def screen_size():
"""
Provides the current dimensions of our screen.
@@ -540,33 +528,32 @@ def demo_glyphs():
"""
def _render():
- with raw_screen() as stdscr:
- height, width = stdscr.getmaxyx()
- columns = width / 30
+ height, width = CURSES_SCREEN.getmaxyx()
+ columns = width / 30
- if columns == 0:
- return # not wide enough to show anything
+ if columns == 0:
+ return # not wide enough to show anything
- # mapping of keycodes to their ACS option names (for instance, ACS_LTEE)
+ # 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_'))
+ 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
+ CURSES_SCREEN.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)
+ for keycode in sorted(acs_options.keys()):
+ CURSES_SCREEN.addstr(y, x * 30, '%s (%i)' % (acs_options[keycode], keycode))
+ CURSES_SCREEN.addch(y, (x * 30) + 25, keycode)
- x += 1
+ x += 1
- if x >= columns:
- x, y = 0, y + 1
+ if x >= columns:
+ x, y = 0, y + 1
- if y >= height:
- break
+ if y >= height:
+ break
- stdscr.getch() # quit on keyboard input
+ CURSES_SCREEN.getch() # quit on keyboard input
try:
start(_render, transparent_background = True, cursor = False)
diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index 824db0c..5e7c910 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -481,9 +481,7 @@ class GraphPanel(nyx.panel.Panel):
# don't grow the graph if it's already consuming the whole display
# (plus an extra line for the graph/log gap)
- with nyx.curses.raw_screen() as stdscr:
- max_height = stdscr.getmaxyx()[0] - self.get_top()
-
+ max_height = nyx.curses.screen_size().height - self.get_top()
current_height = self.get_height()
if current_height < max_height + 1:
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits