move cursor to top after search, prompt_input method
This commit is contained in:
15
rtv/page.py
15
rtv/page.py
@@ -5,7 +5,7 @@ import sys
|
|||||||
import praw.errors
|
import praw.errors
|
||||||
|
|
||||||
from .helpers import clean
|
from .helpers import clean
|
||||||
from .curses_helpers import Color, show_notification, show_help
|
from .curses_helpers import Color, show_notification, show_help, text_input
|
||||||
|
|
||||||
__all__ = ['Navigator']
|
__all__ = ['Navigator']
|
||||||
|
|
||||||
@@ -226,6 +226,19 @@ class BasePage(object):
|
|||||||
except praw.errors.LoginOrScopeRequired:
|
except praw.errors.LoginOrScopeRequired:
|
||||||
show_notification(self.stdscr, ['Login to vote'])
|
show_notification(self.stdscr, ['Login to vote'])
|
||||||
|
|
||||||
|
def prompt_input(self, prompt):
|
||||||
|
"""Prompt the user for input"""
|
||||||
|
attr = curses.A_BOLD | Color.CYAN
|
||||||
|
n_rows, n_cols = self.stdscr.getmaxyx()
|
||||||
|
self.stdscr.addstr(n_rows - 1, 0, prompt, attr)
|
||||||
|
self.stdscr.refresh()
|
||||||
|
window = self.stdscr.derwin(1, n_cols - len(prompt),
|
||||||
|
n_rows - 1, len(prompt))
|
||||||
|
window.attrset(attr)
|
||||||
|
|
||||||
|
out = text_input(window)
|
||||||
|
return out
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
|
||||||
n_rows, n_cols = self.stdscr.getmaxyx()
|
n_rows, n_cols = self.stdscr.getmaxyx()
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from .submission import SubmissionPage
|
|||||||
from .content import SubredditContent
|
from .content import SubredditContent
|
||||||
from .helpers import clean, open_browser
|
from .helpers import clean, open_browser
|
||||||
from .curses_helpers import (BULLET, UARROW, DARROW, Color, LoadScreen,
|
from .curses_helpers import (BULLET, UARROW, DARROW, Color, LoadScreen,
|
||||||
text_input, show_notification)
|
show_notification)
|
||||||
|
|
||||||
__all__ = ['opened_links', 'SubredditController', 'SubredditPage']
|
__all__ = ['opened_links', 'SubredditController', 'SubredditPage']
|
||||||
|
|
||||||
@@ -52,19 +52,13 @@ class SubredditPage(BasePage):
|
|||||||
|
|
||||||
@SubredditController.register('f')
|
@SubredditController.register('f')
|
||||||
def search_subreddit(self, name=None):
|
def search_subreddit(self, name=None):
|
||||||
|
"""Open a prompt to search the subreddit"""
|
||||||
name = name or self.content.name
|
name = name or self.content.name
|
||||||
attr = curses.A_BOLD | Color.CYAN
|
|
||||||
prompt = 'Search this Subreddit: '
|
prompt = 'Search this Subreddit: '
|
||||||
n_rows, n_cols = self.stdscr.getmaxyx()
|
search = self.prompt_input(prompt)
|
||||||
self.stdscr.addstr(n_rows - 1, 0, prompt, attr)
|
|
||||||
self.stdscr.refresh()
|
|
||||||
window = self.stdscr.derwin(1, n_cols - len(prompt),
|
|
||||||
n_rows - 1, len(prompt))
|
|
||||||
window.attrset(attr)
|
|
||||||
|
|
||||||
search = text_input(window)
|
|
||||||
if search is not None:
|
if search is not None:
|
||||||
try:
|
try:
|
||||||
|
self.nav.cursor_index = 0
|
||||||
self.content = SubredditContent.from_name(self.reddit, name,
|
self.content = SubredditContent.from_name(self.reddit, name,
|
||||||
self.loader, search=search)
|
self.loader, search=search)
|
||||||
except:
|
except:
|
||||||
@@ -72,20 +66,11 @@ class SubredditPage(BasePage):
|
|||||||
|
|
||||||
@SubredditController.register('/')
|
@SubredditController.register('/')
|
||||||
def prompt_subreddit(self):
|
def prompt_subreddit(self):
|
||||||
"Open a prompt to type in a new subreddit"
|
"""Open a prompt to type in a new subreddit"""
|
||||||
|
|
||||||
attr = curses.A_BOLD | Color.CYAN
|
|
||||||
prompt = 'Enter Subreddit: /r/'
|
prompt = 'Enter Subreddit: /r/'
|
||||||
n_rows, n_cols = self.stdscr.getmaxyx()
|
name = self.prompt_input(prompt)
|
||||||
self.stdscr.addstr(n_rows - 1, 0, prompt, attr)
|
if name is not None:
|
||||||
self.stdscr.refresh()
|
self.refresh_content(name=name)
|
||||||
window = self.stdscr.derwin(1, n_cols - len(prompt),
|
|
||||||
n_rows - 1, len(prompt))
|
|
||||||
window.attrset(attr)
|
|
||||||
|
|
||||||
out = text_input(window)
|
|
||||||
if out is not None:
|
|
||||||
self.refresh_content(name=out)
|
|
||||||
|
|
||||||
@SubredditController.register(curses.KEY_RIGHT, 'l')
|
@SubredditController.register(curses.KEY_RIGHT, 'l')
|
||||||
def open_submission(self):
|
def open_submission(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user