help message command added

This commit is contained in:
ysakamoto
2015-03-06 03:45:26 -06:00
parent a50317b311
commit b5d2852708
4 changed files with 50 additions and 10 deletions

View File

@@ -31,6 +31,7 @@ Global Commands
`q` : Quit the program. `q` : Quit the program.
`o` : Open the url of the selected item in the default web `o` : Open the url of the selected item in the default web
browser. browser.
`?` : Show the help message.
Subreddit Mode Subreddit Mode
Right or `Enter` : Open the currently selected submission in a new page. 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 .content import SubmissionContent
from .page import BasePage from .page import BasePage
from .utils import LoadScreen, Color, ESCAPE from .utils import LoadScreen, Color, ESCAPE, display_message, help_msg
class SubmissionPage(BasePage): class SubmissionPage(BasePage):
@@ -54,6 +54,9 @@ class SubmissionPage(BasePage):
elif cmd in (ESCAPE, curses.KEY_LEFT, ord('h')): elif cmd in (ESCAPE, curses.KEY_LEFT, ord('h')):
break break
elif cmd == ord('?'):
display_message(self.stdscr, help_msg)
elif cmd == ord('q'): elif cmd == ord('q'):
sys.exit() sys.exit()

View File

@@ -7,7 +7,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, ESCAPE from .utils import LoadScreen, text_input, display_message, Color, ESCAPE, help_msg
class SubredditPage(BasePage): class SubredditPage(BasePage):
@@ -52,6 +52,9 @@ class SubredditPage(BasePage):
elif cmd == curses.KEY_RESIZE: elif cmd == curses.KEY_RESIZE:
self.draw() self.draw()
elif cmd == ord('?'):
display_message(self.stdscr, help_msg)
elif cmd == ord('q'): elif cmd == ord('q'):
sys.exit() sys.exit()
@@ -132,4 +135,4 @@ class SubredditPage(BasePage):
text = '{author}'.format(**data) text = '{author}'.format(**data)
win.addnstr(row, 1, text, n_cols-1, curses.A_BOLD) win.addnstr(row, 1, text, n_cols-1, curses.A_BOLD)
text = ' {subreddit}'.format(**data) text = ' {subreddit}'.format(**data)
win.addnstr(text, n_cols - win.getyx()[1], Color.YELLOW) win.addnstr(text, n_cols - win.getyx()[1], Color.YELLOW)

View File

@@ -16,6 +16,27 @@ from .errors import EscapePressed
ESCAPE = 27 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.
"""
help_msg = help_msg.split("\n")
class Color(object): class Color(object):
COLORS = { COLORS = {
@@ -118,17 +139,29 @@ def text_input(window):
def display_message(stdscr, message): def display_message(stdscr, message):
"Display a message box at the center of the screen and wait for a keypress" "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() n_rows, n_cols = stdscr.getmaxyx()
s_row = (n_rows - 2) // 2
s_col = (n_cols - message_len - 1) // 2 if type(message) == list:
window = stdscr.derwin(3, message_len+2, s_row, s_col) message_len = max(map(len, message))
s_row = (n_rows - len(message)) // 2
s_col = (n_cols - message_len - 1) // 2
window = stdscr.derwin(len(message) + 2, message_len + 3, s_row, s_col)
else:
message_len = len(message)
s_row = (n_rows - 2) // 2
s_col = (n_cols - message_len - 1) // 2
window = stdscr.derwin(10, 3, s_row, s_col)
window.erase() window.erase()
window.border() window.border()
window.addstr(1, 1, message)
window.refresh()
if type(message) == list:
for i in range(len(message)):
window.addstr(i + 1, 1, message[i])
else:
window.addstr(1, 1, message)
window.refresh()
stdscr.getch() stdscr.getch()
window.clear() window.clear()
@@ -250,4 +283,4 @@ def curses_session():
stdscr.keypad(0) stdscr.keypad(0)
curses.echo() curses.echo()
curses.nocbreak() curses.nocbreak()
curses.endwin() curses.endwin()