From df919039009840f3838fb555476e8fce72305764 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Thu, 12 Feb 2015 20:40:51 -0800 Subject: [PATCH] Clean up, simplified key commands. --- rtv/page.py | 1 - rtv/submission.py | 6 +++--- rtv/subreddit.py | 4 ++-- rtv/utils.py | 6 ++++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/rtv/page.py b/rtv/page.py index dac19fe..e7325bf 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -38,7 +38,6 @@ class Navigator(object): valid, redraw = True, False - # TODO: add variable movement forward = ((direction*self.step) > 0) if forward: diff --git a/rtv/submission.py b/rtv/submission.py index 1233e28..54ab672 100644 --- a/rtv/submission.py +++ b/rtv/submission.py @@ -5,7 +5,7 @@ import six from .content import SubmissionContent from .page import BasePage -from .utils import LoadScreen, Color +from .utils import LoadScreen, Color, ESCAPE class SubmissionPage(BasePage): @@ -42,7 +42,7 @@ class SubmissionPage(BasePage): self.draw() # Show / hide a comment tree - elif cmd in (curses.KEY_RIGHT, ord(' ')): + elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER): self.toggle_comment() self.draw() @@ -50,7 +50,7 @@ class SubmissionPage(BasePage): self.draw() # Go back - elif cmd in (ord('b'), 27, curses.KEY_LEFT): + elif cmd in (ESCAPE, curses.KEY_LEFT): break # Quit diff --git a/rtv/subreddit.py b/rtv/subreddit.py index 0627d8b..93a6c10 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -6,7 +6,7 @@ from .errors import SubredditNameError from .page import BasePage from .submission import SubmissionPage from .content import SubredditContent -from .utils import LoadScreen, text_input, display_message, Color +from .utils import LoadScreen, text_input, display_message, Color, ESCAPE class SubredditPage(BasePage): @@ -34,7 +34,7 @@ class SubredditPage(BasePage): self.clear_input_queue() # View submission - elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord(' '), 10): + elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER): self.open_submission() self.draw() diff --git a/rtv/utils.py b/rtv/utils.py index 4a9bb3e..bd4fb6a 100644 --- a/rtv/utils.py +++ b/rtv/utils.py @@ -7,6 +7,8 @@ from contextlib import contextmanager from .errors import EscapePressed +ESCAPE = 27 + class Color(object): COLORS = { @@ -57,7 +59,7 @@ def text_input(window): def validate(ch): "Filters characters for special key sequences" - if ch == 27: + if ch == ESCAPE: raise EscapePressed return ch @@ -166,7 +168,7 @@ def curses_session(): # Curses must wait for some time after the Escape key is pressed to see # check if it is the beginning of an escape sequence indicating a # special key. The default wait time is 1 second, which means that - # getch() will not return the escape key (ord(27)), until a full second + # getch() will not return the escape key (27), until a full second # after it has been pressed. Turn this down to 25 ms, which is close to # what VIM uses. # http://stackoverflow.com/questions/27372068