Merge branch 'master' of https://github.com/michael-lazar/rtv
This commit is contained in:
@@ -15,6 +15,7 @@ from .curses_helpers import curses_session
|
|||||||
from .submission import SubmissionPage
|
from .submission import SubmissionPage
|
||||||
from .subreddit import SubredditPage
|
from .subreddit import SubredditPage
|
||||||
from .docs import *
|
from .docs import *
|
||||||
|
from .__version__ import __version__
|
||||||
|
|
||||||
__all__ = []
|
__all__ = []
|
||||||
|
|
||||||
@@ -68,6 +69,13 @@ def main():
|
|||||||
args = command_line()
|
args = command_line()
|
||||||
local_config = load_config()
|
local_config = load_config()
|
||||||
|
|
||||||
|
# set the terminal title
|
||||||
|
title = 'rtv {0}'.format(__version__)
|
||||||
|
if os.name == 'nt':
|
||||||
|
os.system('title {0}'.format(title))
|
||||||
|
else:
|
||||||
|
sys.stdout.write("\x1b]2;{0}\x07".format(title))
|
||||||
|
|
||||||
# Fill in empty arguments with config file values. Paramaters explicitly
|
# Fill in empty arguments with config file values. Paramaters explicitly
|
||||||
# typed on the command line will take priority over config file params.
|
# typed on the command line will take priority over config file params.
|
||||||
for key, val in local_config.items():
|
for key, val in local_config.items():
|
||||||
|
|||||||
@@ -52,12 +52,14 @@ def show_notification(stdscr, message):
|
|||||||
for index, line in enumerate(message, start=1):
|
for index, line in enumerate(message, start=1):
|
||||||
window.addstr(index, 1, line)
|
window.addstr(index, 1, line)
|
||||||
window.refresh()
|
window.refresh()
|
||||||
stdscr.getch()
|
ch = stdscr.getch()
|
||||||
|
|
||||||
window.clear()
|
window.clear()
|
||||||
window = None
|
window = None
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
|
|
||||||
|
return ch
|
||||||
|
|
||||||
|
|
||||||
def show_help(stdscr):
|
def show_help(stdscr):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ Global Commands
|
|||||||
`r` : Refresh the current page
|
`r` : Refresh the current page
|
||||||
`q` : Quit the program
|
`q` : Quit the program
|
||||||
`ENTER` or `o` : Open the selected item in the default web browser
|
`ENTER` or `o` : Open the selected item in the default web browser
|
||||||
|
`u` : Log in
|
||||||
`?` : Show this help message
|
`?` : Show this help message
|
||||||
|
|
||||||
Subreddit Mode
|
Subreddit Mode
|
||||||
|
|||||||
57
rtv/page.py
57
rtv/page.py
@@ -6,6 +6,7 @@ import praw.errors
|
|||||||
|
|
||||||
from .helpers import clean
|
from .helpers import clean
|
||||||
from .curses_helpers import Color, show_notification, show_help, text_input
|
from .curses_helpers import Color, show_notification, show_help, text_input
|
||||||
|
from .docs import AGENT
|
||||||
|
|
||||||
__all__ = ['Navigator']
|
__all__ = ['Navigator']
|
||||||
|
|
||||||
@@ -226,17 +227,59 @@ 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):
|
@BaseController.register('u')
|
||||||
|
def login(self):
|
||||||
|
"""
|
||||||
|
Prompt to log into the user's account. Log out if the user is already
|
||||||
|
logged in.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.reddit.is_logged_in():
|
||||||
|
self.logout()
|
||||||
|
return
|
||||||
|
|
||||||
|
username = self.prompt_input('Enter username:')
|
||||||
|
password = self.prompt_input('Enter password:', hide=True)
|
||||||
|
if not username or not password:
|
||||||
|
curses.flash()
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.reddit.login(username, password)
|
||||||
|
except praw.errors.InvalidUserPass:
|
||||||
|
show_notification(self.stdscr, ['Invalid user/pass'])
|
||||||
|
else:
|
||||||
|
show_notification(self.stdscr, ['Logged in'])
|
||||||
|
|
||||||
|
def logout(self):
|
||||||
|
"""
|
||||||
|
Prompt to log out of the user's account.
|
||||||
|
"""
|
||||||
|
|
||||||
|
ch = self.prompt_input("Log out? (y/n):")
|
||||||
|
if ch == 'y':
|
||||||
|
self.reddit.clear_authentication()
|
||||||
|
show_notification(self.stdscr, ['Logged out'])
|
||||||
|
elif ch != 'n':
|
||||||
|
curses.flash()
|
||||||
|
|
||||||
|
def prompt_input(self, prompt, hide=False):
|
||||||
"""Prompt the user for input"""
|
"""Prompt the user for input"""
|
||||||
attr = curses.A_BOLD | Color.CYAN
|
attr = curses.A_BOLD | Color.CYAN
|
||||||
n_rows, n_cols = self.stdscr.getmaxyx()
|
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)
|
if hide:
|
||||||
|
prompt += ' ' * (n_cols - len(prompt) - 1)
|
||||||
|
self.stdscr.addstr(n_rows-1, 0, prompt, attr)
|
||||||
|
out = self.stdscr.getstr(n_rows-1, 1)
|
||||||
|
else:
|
||||||
|
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
|
return out
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user