Fixed help message crashing on small terminals.
This commit is contained in:
29
rtv/main.py
29
rtv/main.py
@@ -4,7 +4,7 @@ import praw
|
|||||||
from requests.exceptions import ConnectionError, HTTPError
|
from requests.exceptions import ConnectionError, HTTPError
|
||||||
|
|
||||||
from rtv.errors import SubmissionURLError, SubredditNameError
|
from rtv.errors import SubmissionURLError, SubredditNameError
|
||||||
from rtv.utils import curses_session, load_config
|
from rtv.utils import curses_session, load_config, HELP
|
||||||
from rtv.subreddit import SubredditPage
|
from rtv.subreddit import SubredditPage
|
||||||
from rtv.submission import SubmissionPage
|
from rtv.submission import SubmissionPage
|
||||||
|
|
||||||
@@ -15,38 +15,17 @@ terminal window.
|
|||||||
|
|
||||||
# TODO: Figure out a way to sync this with the README
|
# TODO: Figure out a way to sync this with the README
|
||||||
epilog = """
|
epilog = """
|
||||||
Usage
|
Controls
|
||||||
-----
|
-----
|
||||||
RTV currently supports browsing both subreddits and individual submissions.
|
RTV currently supports browsing both subreddits and individual submissions.
|
||||||
In each mode the controls are slightly different. In subreddit mode you can
|
In each mode the controls are slightly different. In subreddit mode you can
|
||||||
browse through the top submissions on either the front page or a specific
|
browse through the top submissions on either the front page or a specific
|
||||||
subreddit. In submission mode you can view the self text for a submission and
|
subreddit. In submission mode you can view the self text for a submission and
|
||||||
browse comments.
|
browse comments.
|
||||||
|
|
||||||
Global Commands
|
|
||||||
Arrow Keys or `hjkl`: RTV supports both the arrow keys and vim bindings for
|
|
||||||
navigation. Move up and down to scroll through items
|
|
||||||
on the page.
|
|
||||||
`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 the 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. For
|
|
||||||
example, pressing `/` and typing "python" will open
|
|
||||||
"/r/python". You can return to Reddit's front page
|
|
||||||
by using the alias "/r/front".
|
|
||||||
|
|
||||||
Submission Mode
|
|
||||||
Right or `Enter` : Toggle the currently selected comment between hidden
|
|
||||||
and visible. Alternatively, load addition comments
|
|
||||||
identified by "[+] more comments".
|
|
||||||
Left : Exit the submission page and return to the subreddit.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
epilog += HELP
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
|
|||||||
45
rtv/utils.py
45
rtv/utils.py
@@ -16,25 +16,23 @@ from .errors import EscapePressed
|
|||||||
|
|
||||||
ESCAPE = 27
|
ESCAPE = 27
|
||||||
|
|
||||||
help_msg = """Global Commands
|
HELP = """
|
||||||
Arrow Keys or `hjkl`: Navigations.
|
Global Commands
|
||||||
`r` or `F5` : Refresh the current page.
|
`UP/DOWN` or `j/k` : Scroll to the prev/next item
|
||||||
`q` : Quit the program.
|
`r` or `F5` : Refresh the current page
|
||||||
`o` : Open the url of the selected item in the default web
|
`q` : Quit the program
|
||||||
browser.
|
`o` : Open the selected item in the default web browser
|
||||||
`?` : Show this help message.
|
`?` : Show this help message
|
||||||
|
|
||||||
Subreddit Mode
|
Subreddit Mode
|
||||||
Right or `Enter` : Open the currently selected submission in a new page.
|
`RIGHT` or `l` : View comments for the selected submission
|
||||||
`/` : Open a prompt to switch to a different subreddit.
|
`/` : Open a prompt to switch subreddits
|
||||||
|
|
||||||
Submission Mode
|
Submission Mode
|
||||||
Right or `Enter` : Toggle the currently selected comment between hidden
|
`LEFT` or `h` : Return to subreddit mode
|
||||||
and visible.
|
`RIGHT` or `l` : Fold the selected comment, or load additional comments
|
||||||
Left : Exit the submission page and return to the subreddit.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Color(object):
|
class Color(object):
|
||||||
|
|
||||||
COLORS = {
|
COLORS = {
|
||||||
@@ -139,17 +137,24 @@ def display_message(stdscr, message):
|
|||||||
|
|
||||||
n_rows, n_cols = stdscr.getmaxyx()
|
n_rows, n_cols = stdscr.getmaxyx()
|
||||||
|
|
||||||
box_width = max(map(len, message))
|
box_width = max(map(len, message)) + 2
|
||||||
box_height = len(message)
|
box_height = len(message) + 2
|
||||||
|
|
||||||
|
# Make sure the window is large enough to fit the message
|
||||||
|
# TODO: Should find a better way to display the message in this situation
|
||||||
|
if (box_width > n_cols) or (box_height > n_rows):
|
||||||
|
curses.flash()
|
||||||
|
return
|
||||||
|
|
||||||
s_row = (n_rows - box_height) // 2
|
s_row = (n_rows - box_height) // 2
|
||||||
s_col = (n_cols - box_width - 1) // 2
|
s_col = (n_cols - box_width) // 2
|
||||||
window = stdscr.derwin(box_height + 2, box_width + 3, s_row, s_col)
|
window = stdscr.derwin(box_height, box_width, s_row, s_col)
|
||||||
|
|
||||||
window.erase()
|
window.erase()
|
||||||
window.border()
|
window.border()
|
||||||
|
|
||||||
for i in range(box_height):
|
for index, line in enumerate(message, start=1):
|
||||||
window.addstr(i + 1, 1, message[i])
|
window.addstr(index, 1, line)
|
||||||
|
|
||||||
window.refresh()
|
window.refresh()
|
||||||
stdscr.getch()
|
stdscr.getch()
|
||||||
@@ -163,7 +168,7 @@ def display_help(stdscr):
|
|||||||
"""Display a help message box at the center of the screen and wait for a
|
"""Display a help message box at the center of the screen and wait for a
|
||||||
keypress"""
|
keypress"""
|
||||||
|
|
||||||
help_msgs = help_msg.split("\n")
|
help_msgs = HELP.split("\n")
|
||||||
display_message(stdscr, help_msgs)
|
display_message(stdscr, help_msgs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user