Merge branch 'yskmt-help-msg'
This commit is contained in:
@@ -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.
|
||||||
|
|||||||
@@ -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_help
|
||||||
|
|
||||||
class SubmissionPage(BasePage):
|
class SubmissionPage(BasePage):
|
||||||
|
|
||||||
@@ -54,6 +54,10 @@ 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_help(self.stdscr)
|
||||||
|
self.draw()
|
||||||
|
|
||||||
elif cmd == ord('q'):
|
elif cmd == ord('q'):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|||||||
@@ -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, display_help
|
||||||
|
|
||||||
class SubredditPage(BasePage):
|
class SubredditPage(BasePage):
|
||||||
|
|
||||||
@@ -52,6 +52,10 @@ class SubredditPage(BasePage):
|
|||||||
elif cmd == curses.KEY_RESIZE:
|
elif cmd == curses.KEY_RESIZE:
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
|
elif cmd == ord('?'):
|
||||||
|
display_help(self.stdscr)
|
||||||
|
self.draw()
|
||||||
|
|
||||||
elif cmd == ord('q'):
|
elif cmd == ord('q'):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
@@ -67,7 +71,7 @@ class SubredditPage(BasePage):
|
|||||||
self.reddit, name, self.loader)
|
self.reddit, name, self.loader)
|
||||||
|
|
||||||
except (SubredditNameError, HTTPError):
|
except (SubredditNameError, HTTPError):
|
||||||
display_message(self.stdscr, 'Invalid Subreddit')
|
display_message(self.stdscr, ['Invalid Subreddit'])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.nav.page_index, self.nav.cursor_index = 0, 0
|
self.nav.page_index, self.nav.cursor_index = 0, 0
|
||||||
@@ -132,4 +136,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)
|
||||||
|
|||||||
45
rtv/utils.py
45
rtv/utils.py
@@ -16,6 +16,25 @@ 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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Color(object):
|
class Color(object):
|
||||||
|
|
||||||
COLORS = {
|
COLORS = {
|
||||||
@@ -118,17 +137,21 @@ 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
|
box_width = max(map(len, message))
|
||||||
window = stdscr.derwin(3, message_len+2, s_row, s_col)
|
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.erase()
|
||||||
window.border()
|
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()
|
stdscr.getch()
|
||||||
|
|
||||||
window.clear()
|
window.clear()
|
||||||
@@ -136,6 +159,14 @@ def display_message(stdscr, message):
|
|||||||
stdscr.refresh()
|
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):
|
class LoadScreen(object):
|
||||||
|
|
||||||
def __init__(self, stdscr):
|
def __init__(self, stdscr):
|
||||||
@@ -250,4 +281,4 @@ def curses_session():
|
|||||||
stdscr.keypad(0)
|
stdscr.keypad(0)
|
||||||
curses.echo()
|
curses.echo()
|
||||||
curses.nocbreak()
|
curses.nocbreak()
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
|
|||||||
Reference in New Issue
Block a user