From 9894e2ce1d011b3d89650e2da815bb2f6cf52e98 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Wed, 3 Aug 2016 22:05:13 -0700 Subject: [PATCH] Updated help, switch help screen to PAGER. --- rtv/docs.py | 73 +++++++++++++++++++++++++++--------------- rtv/page.py | 2 +- tests/test_page.py | 6 ++-- tests/test_terminal.py | 8 ++--- 4 files changed, 55 insertions(+), 34 deletions(-) diff --git a/rtv/docs.py b/rtv/docs.py index d967079..6fa15c1 100644 --- a/rtv/docs.py +++ b/rtv/docs.py @@ -17,37 +17,58 @@ Press `?` to open the help screen. """ HELP = """ +Reddit Terminal Viewer + +https://github.com/michael-lazar/rtv +====================== + [Basic Commands] - `j/k` or `UP/DOWN` : Move the cursor up/down - `m/n` or `PgUp/PgDn`: Jump to the previous/next page - `o` or `ENTER` : Open the selected item as a webpage - `1`-`5` : Toggle post order - `r` or `F5` : Refresh page content - `u` : Log in or switch accounts - `?` : Show the help screen - `q/Q` : Quit/Force quit + j/k or ▲/▼ : Move the cursor up/down + m/n or PgUp/PgDn : Jump to the previous/next page + 1-5 : Toggle post order + r or F5 : Refresh page content + u : Log in or switch accounts + ? : Show the help screen + q/Q : Quit/Force quit [Authenticated Commands] - `a/z` : Upvote/downvote - `w` : Save/unsave a post - `c` : Compose a new post or comment - `e` : Edit an existing post or comment - `d` : Delete an existing post or comment - `i` : Display new messages prompt - `s` : Open subscribed subreddits - `S` : Open subscribed multireddits + a/z : Upvote/downvote + c : Compose a new post or comment + e : Edit an existing post or comment + d : Delete an existing post or comment + i : Display new messages prompt + s : View a list of subscribed subreddits + S : View a list of subscribed multireddits + w : Save a submission -[Subreddit Mode] - `l` or `RIGHT` : Enter the selected submission - `/` : Open a prompt to switch subreddits - `f` : Open a prompt to search the current subreddit - 'p' : Toggle between the front page and last visited subreddit +[Subreddit Commands] + l or ► : Enter the selected submission + o or ENTER : Open the submission link with your web browser + / : Open a prompt to switch subreddits + f : Open a prompt to search the current subreddit + p : Return to the front page -[Submission Mode] - `h` or `LEFT` : Return to subreddit mode - `l` or `RIGHT` : Open the selected comment in a new window - `SPACE` : Fold the selected comment, or load additional comments - `b` : Display URLs with urlview +[Submission Commands] + h or ◄ : Return to the subreddit + l or ► : Open the selected comment in a new window + o or ENTER : Open the comment permalink with your web browser + SPACE : Fold the selected comment, or load additional comments + b : Display URLs with urlview + +[Navigating] + The `/` prompt accepts subreddits in the following formats + + - python + - /r/python + - /r/python/new (sort) + - /r/python/controversial-year (sort and order) + - /r/python+linux (multireddit) + - /r/front (front page) + - /u/me (your submissions) + - /u/saved (your saved posts) + - /u/spez (a user's submissions) + - /u/multi-mod/m/android (curated multireddit) + - /domain/python.org (search by domain) """ COMMENT_FILE = """ diff --git a/rtv/page.py b/rtv/page.py index e248d98..40ce64f 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -82,7 +82,7 @@ class Page(object): @PageController.register(Command('HELP')) def show_help(self): - self.term.show_notification(docs.HELP.strip('\n').splitlines()) + self.term.open_pager(docs.HELP.strip()) @PageController.register(Command('SORT_HOT')) def sort_content_hot(self): diff --git a/tests/test_page.py b/tests/test_page.py index 0a721a3..8a4f9ce 100644 --- a/tests/test_page.py +++ b/tests/test_page.py @@ -71,9 +71,9 @@ def test_page_unauthenticated(reddit, terminal, config, oauth): assert sys_exit.called # Show help - page.controller.trigger('?') - message = '[Basic Commands]'.encode('utf-8') - terminal.stdscr.subwin.addstr.assert_any_call(1, 1, message) + with mock.patch('subprocess.Popen') as Popen: + page.controller.trigger('?') + assert Popen.called # Sort content page.controller.trigger('1') diff --git a/tests/test_terminal.py b/tests/test_terminal.py index ad538a7..86cfff5 100644 --- a/tests/test_terminal.py +++ b/tests/test_terminal.py @@ -189,12 +189,12 @@ def test_show_notification(terminal, stdscr, use_ascii): assert stdscr.subwin.addstr.call_count == 3 stdscr.reset_mock() - # The whole message should fit in 40x80 + # The text should be trimmed to fit 40x80 text = HELP.strip().splitlines() terminal.show_notification(text) - assert stdscr.subwin.nlines == len(text) + 2 - assert stdscr.subwin.ncols == 80 - assert stdscr.subwin.addstr.call_count == len(text) + assert stdscr.subwin.nlines == 40 + assert stdscr.subwin.ncols <= 80 + assert stdscr.subwin.addstr.call_count == 38 stdscr.reset_mock() # The text should be trimmed to fit in 20x20