Clean up, simplified key commands.

This commit is contained in:
Michael Lazar
2015-02-12 20:40:51 -08:00
parent 901c094dd5
commit df91903900
4 changed files with 9 additions and 8 deletions

View File

@@ -38,7 +38,6 @@ class Navigator(object):
valid, redraw = True, False valid, redraw = True, False
# TODO: add variable movement
forward = ((direction*self.step) > 0) forward = ((direction*self.step) > 0)
if forward: if forward:

View File

@@ -5,7 +5,7 @@ import six
from .content import SubmissionContent from .content import SubmissionContent
from .page import BasePage from .page import BasePage
from .utils import LoadScreen, Color from .utils import LoadScreen, Color, ESCAPE
class SubmissionPage(BasePage): class SubmissionPage(BasePage):
@@ -42,7 +42,7 @@ class SubmissionPage(BasePage):
self.draw() self.draw()
# Show / hide a comment tree # 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.toggle_comment()
self.draw() self.draw()
@@ -50,7 +50,7 @@ class SubmissionPage(BasePage):
self.draw() self.draw()
# Go back # Go back
elif cmd in (ord('b'), 27, curses.KEY_LEFT): elif cmd in (ESCAPE, curses.KEY_LEFT):
break break
# Quit # Quit

View File

@@ -6,7 +6,7 @@ from .errors import SubredditNameError
from .page import BasePage from .page import BasePage
from .submission import SubmissionPage from .submission import SubmissionPage
from .content import SubredditContent 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): class SubredditPage(BasePage):
@@ -34,7 +34,7 @@ class SubredditPage(BasePage):
self.clear_input_queue() self.clear_input_queue()
# View submission # 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.open_submission()
self.draw() self.draw()

View File

@@ -7,6 +7,8 @@ from contextlib import contextmanager
from .errors import EscapePressed from .errors import EscapePressed
ESCAPE = 27
class Color(object): class Color(object):
COLORS = { COLORS = {
@@ -57,7 +59,7 @@ def text_input(window):
def validate(ch): def validate(ch):
"Filters characters for special key sequences" "Filters characters for special key sequences"
if ch == 27: if ch == ESCAPE:
raise EscapePressed raise EscapePressed
return ch return ch
@@ -166,7 +168,7 @@ def curses_session():
# Curses must wait for some time after the Escape key is pressed to see # 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 # check if it is the beginning of an escape sequence indicating a
# special key. The default wait time is 1 second, which means that # 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 # after it has been pressed. Turn this down to 25 ms, which is close to
# what VIM uses. # what VIM uses.
# http://stackoverflow.com/questions/27372068 # http://stackoverflow.com/questions/27372068