login with '+' key
This commit is contained in:
@@ -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
|
||||||
|
`+` : Log in
|
||||||
`?` : Show this help message
|
`?` : Show this help message
|
||||||
|
|
||||||
Subreddit Mode
|
Subreddit Mode
|
||||||
|
|||||||
40
rtv/page.py
40
rtv/page.py
@@ -226,17 +226,43 @@ 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('+')
|
||||||
|
def login(self):
|
||||||
|
username = self.prompt_input('Enter username: ')
|
||||||
|
password = self.prompt_input('Enter password: ', hide=True)
|
||||||
|
|
||||||
|
if (username == '') or (password == ''):
|
||||||
|
curses.flash()
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
self.reddit.login(username, password)
|
||||||
|
|
||||||
|
except praw.errors.InvalidUserPass:
|
||||||
|
show_notification(self.stdscr,
|
||||||
|
['Invalid password for username: {}'.format(username)])
|
||||||
|
else:
|
||||||
|
show_notification(self.stdscr,
|
||||||
|
['Successfully logged in as: {}'.format(username)])
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
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:
|
||||||
|
self.stdscr.addstr(n_rows - 1, 0, prompt+' '*(n_rows-1-len(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