@@ -7,9 +7,9 @@ from .exceptions import SubmissionError, SubredditError, AccountError
|
||||
from .helpers import humanize_timestamp, wrap_text, strip_subreddit_url
|
||||
|
||||
__all__ = ['SubredditContent', 'SubmissionContent']
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BaseContent(object):
|
||||
|
||||
def get(self, index, n_cols):
|
||||
|
||||
@@ -21,6 +21,7 @@ __all__ = ['ESCAPE', 'get_gold', 'show_notification', 'show_help',
|
||||
# http://bugs.python.org/issue21088
|
||||
ESCAPE = 27
|
||||
|
||||
|
||||
def get_gold():
|
||||
"""
|
||||
Return the guilded symbol.
|
||||
@@ -30,6 +31,7 @@ def get_gold():
|
||||
attr = curses.A_BOLD | Color.YELLOW
|
||||
return symbol, attr
|
||||
|
||||
|
||||
def get_arrow(likes):
|
||||
"""
|
||||
Return the vote symbol to display, based on the `likes` paramater.
|
||||
@@ -305,7 +307,7 @@ def prompt_input(window, prompt, hide=False):
|
||||
window.addstr(n_rows - 1, 0, prompt, attr)
|
||||
window.refresh()
|
||||
subwin = window.derwin(1, n_cols - len(prompt),
|
||||
n_rows - 1, len(prompt))
|
||||
n_rows - 1, len(prompt))
|
||||
subwin.attrset(attr)
|
||||
out = text_input(subwin)
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from .exceptions import ProgramError
|
||||
__all__ = ['open_browser', 'clean', 'wrap_text', 'strip_textpad',
|
||||
'strip_subreddit_url', 'humanize_timestamp', 'open_editor']
|
||||
|
||||
|
||||
def clean(string, n_cols=None):
|
||||
"""
|
||||
Required reading!
|
||||
@@ -49,6 +50,7 @@ def clean(string, n_cols=None):
|
||||
string = string.encode('utf-8')
|
||||
return string
|
||||
|
||||
|
||||
def open_editor(data=''):
|
||||
"""
|
||||
Open a temporary file using the system's default editor.
|
||||
@@ -124,6 +126,7 @@ def open_browser(url):
|
||||
webbrowser.open_new_tab(url)
|
||||
curses.doupdate()
|
||||
|
||||
|
||||
def wrap_text(text, width):
|
||||
"""
|
||||
Wrap text paragraphs to the given character width while preserving newlines.
|
||||
|
||||
@@ -44,6 +44,7 @@ def save_history(history):
|
||||
# Ignore unicode URLS, may want to handle this at some point
|
||||
continue
|
||||
|
||||
|
||||
class OrderedSet(object):
|
||||
"""
|
||||
A simple implementation of an ordered set. A set is used to check
|
||||
|
||||
@@ -15,9 +15,9 @@ from .curses_helpers import (Color, show_notification, show_help, text_input,
|
||||
from .docs import COMMENT_EDIT_FILE, SUBMISSION_FILE
|
||||
|
||||
__all__ = ['Navigator', 'BaseController', 'BasePage']
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Navigator(object):
|
||||
"""
|
||||
Handles math behind cursor movement and screen paging.
|
||||
@@ -155,6 +155,7 @@ class Navigator(object):
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class SafeCaller(object):
|
||||
|
||||
def __init__(self, window):
|
||||
@@ -186,6 +187,7 @@ class SafeCaller(object):
|
||||
_logger.exception(e)
|
||||
return True
|
||||
|
||||
|
||||
class BaseController(object):
|
||||
"""
|
||||
Event handler for triggering functions with curses keypresses.
|
||||
|
||||
@@ -13,9 +13,9 @@ from .curses_helpers import (Color, LoadScreen, get_arrow, get_gold, add_line,
|
||||
from .docs import COMMENT_FILE
|
||||
|
||||
__all__ = ['SubmissionController', 'SubmissionPage']
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SubmissionController(BaseController):
|
||||
character_map = {}
|
||||
|
||||
|
||||
@@ -17,11 +17,10 @@ from .curses_helpers import (Color, LoadScreen, add_line, get_arrow, get_gold,
|
||||
show_notification, prompt_input)
|
||||
|
||||
__all__ = ['history', 'SubredditController', 'SubredditPage']
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
history = load_history()
|
||||
|
||||
|
||||
@atexit.register
|
||||
def save_links():
|
||||
global history
|
||||
@@ -80,7 +79,7 @@ class SubredditPage(BasePage):
|
||||
try:
|
||||
self.content = SubredditContent.from_name(
|
||||
self.reddit, name, self.loader, query=query)
|
||||
except IndexError: # if there are no submissions
|
||||
except IndexError: # if there are no submissions
|
||||
show_notification(self.stdscr, ['No results found'])
|
||||
else:
|
||||
self.nav = Navigator(self.content.get)
|
||||
|
||||
Reference in New Issue
Block a user