Merge branch 'yskmt-help-msg'

This commit is contained in:
Michael Lazar
2015-03-07 13:02:08 -08:00
4 changed files with 51 additions and 11 deletions

View File

@@ -31,6 +31,7 @@ Global Commands
`q` : Quit the program.
`o` : Open the url of the selected item in the default web
browser.
`?` : Show the help message.
Subreddit Mode
Right or `Enter` : Open the currently selected submission in a new page.

View File

@@ -6,7 +6,7 @@ import six
from .content import SubmissionContent
from .page import BasePage
from .utils import LoadScreen, Color, ESCAPE
from .utils import LoadScreen, Color, ESCAPE, display_help
class SubmissionPage(BasePage):
@@ -54,6 +54,10 @@ class SubmissionPage(BasePage):
elif cmd in (ESCAPE, curses.KEY_LEFT, ord('h')):
break
elif cmd == ord('?'):
display_help(self.stdscr)
self.draw()
elif cmd == ord('q'):
sys.exit()

View File

@@ -7,7 +7,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, ESCAPE
from .utils import LoadScreen, text_input, display_message, Color, ESCAPE, display_help
class SubredditPage(BasePage):
@@ -52,6 +52,10 @@ class SubredditPage(BasePage):
elif cmd == curses.KEY_RESIZE:
self.draw()
elif cmd == ord('?'):
display_help(self.stdscr)
self.draw()
elif cmd == ord('q'):
sys.exit()
@@ -67,7 +71,7 @@ class SubredditPage(BasePage):
self.reddit, name, self.loader)
except (SubredditNameError, HTTPError):
display_message(self.stdscr, 'Invalid Subreddit')
display_message(self.stdscr, ['Invalid Subreddit'])
else:
self.nav.page_index, self.nav.cursor_index = 0, 0

View File

@@ -16,6 +16,25 @@ from .errors import EscapePressed
ESCAPE = 27
help_msg = """Global Commands
Arrow Keys or `hjkl`: Navigations.
`r` or `F5` : Refresh the current page.
`q` : Quit the program.
`o` : Open the url of the selected item in the default web
browser.
`?` : Show this help message.
Subreddit Mode
Right or `Enter` : Open the currently selected submission in a new page.
`/` : Open a prompt to switch to a different subreddit.
Submission Mode
Right or `Enter` : Toggle the currently selected comment between hidden
and visible.
Left : Exit the submission page and return to the subreddit.
"""
class Color(object):
COLORS = {
@@ -118,17 +137,21 @@ def text_input(window):
def display_message(stdscr, message):
"Display a message box at the center of the screen and wait for a keypress"
message_len = len(message)
n_rows, n_cols = stdscr.getmaxyx()
s_row = (n_rows - 2) // 2
s_col = (n_cols - message_len - 1) // 2
window = stdscr.derwin(3, message_len+2, s_row, s_col)
box_width = max(map(len, message))
box_height = len(message)
s_row = (n_rows - box_height) // 2
s_col = (n_cols - box_width - 1) // 2
window = stdscr.derwin(box_height + 2, box_width + 3, s_row, s_col)
window.erase()
window.border()
window.addstr(1, 1, message)
window.refresh()
for i in range(box_height):
window.addstr(i + 1, 1, message[i])
window.refresh()
stdscr.getch()
window.clear()
@@ -136,6 +159,14 @@ def display_message(stdscr, message):
stdscr.refresh()
def display_help(stdscr):
"""Display a help message box at the center of the screen and wait for a
keypress"""
help_msgs = help_msg.split("\n")
display_message(stdscr, help_msgs)
class LoadScreen(object):
def __init__(self, stdscr):