Refactored vote arrow logic.
This commit is contained in:
@@ -11,7 +11,7 @@ from .exceptions import EscapeInterrupt
|
|||||||
|
|
||||||
__all__ = ['ESCAPE', 'UARROW', 'DARROW', 'BULLET', 'show_notification',
|
__all__ = ['ESCAPE', 'UARROW', 'DARROW', 'BULLET', 'show_notification',
|
||||||
'show_help', 'LoadScreen', 'Color', 'text_input', 'curses_session',
|
'show_help', 'LoadScreen', 'Color', 'text_input', 'curses_session',
|
||||||
'prompt_input', 'add_line']
|
'prompt_input', 'add_line', 'get_arrow']
|
||||||
|
|
||||||
ESCAPE = 27
|
ESCAPE = 27
|
||||||
|
|
||||||
@@ -25,6 +25,20 @@ DARROW = u'\u25bc'.encode('utf-8')
|
|||||||
BULLET = u'\u2022'.encode('utf-8')
|
BULLET = u'\u2022'.encode('utf-8')
|
||||||
GOLD = u'\u272A'.encode('utf-8')
|
GOLD = u'\u272A'.encode('utf-8')
|
||||||
|
|
||||||
|
def get_arrow(likes):
|
||||||
|
"""
|
||||||
|
Return the vote symbol to display, based on the `likes` paramater.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if likes is None:
|
||||||
|
symbol, attr = BULLET, curses.A_BOLD
|
||||||
|
elif likes:
|
||||||
|
symbol, attr = UARROW, curses.A_BOLD | Color.GREEN
|
||||||
|
else:
|
||||||
|
symbol, attr = DARROW, curses.A_BOLD | Color.RED
|
||||||
|
return symbol, attr
|
||||||
|
|
||||||
|
|
||||||
def add_line(window, text, row=None, col=None, attr=None):
|
def add_line(window, text, row=None, col=None, attr=None):
|
||||||
"""
|
"""
|
||||||
Unicode aware version of curses's built-in addnstr method.
|
Unicode aware version of curses's built-in addnstr method.
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import praw.errors
|
|||||||
from .content import SubmissionContent
|
from .content import SubmissionContent
|
||||||
from .page import BasePage, Navigator, BaseController
|
from .page import BasePage, Navigator, BaseController
|
||||||
from .helpers import open_browser, open_editor
|
from .helpers import open_browser, open_editor
|
||||||
from .curses_helpers import (BULLET, UARROW, DARROW, GOLD, Color, LoadScreen,
|
from .curses_helpers import (GOLD, Color, LoadScreen, get_arrow, add_line,
|
||||||
show_notification, text_input, add_line)
|
show_notification, text_input)
|
||||||
from .docs import COMMENT_FILE
|
from .docs import COMMENT_FILE
|
||||||
|
|
||||||
__all__ = ['SubmissionController', 'SubmissionPage']
|
__all__ = ['SubmissionController', 'SubmissionPage']
|
||||||
@@ -166,14 +166,8 @@ class SubmissionPage(BasePage):
|
|||||||
attr = curses.A_BOLD | Color.YELLOW
|
attr = curses.A_BOLD | Color.YELLOW
|
||||||
add_line(win, u'{flair} '.format(**data), attr=attr)
|
add_line(win, u'{flair} '.format(**data), attr=attr)
|
||||||
|
|
||||||
if data['likes'] is None:
|
text, attr = get_arrow(likes)
|
||||||
text, attr = BULLET, curses.A_BOLD
|
|
||||||
elif data['likes']:
|
|
||||||
text, attr = UARROW, (curses.A_BOLD | Color.GREEN)
|
|
||||||
else:
|
|
||||||
text, attr = DARROW, (curses.A_BOLD | Color.RED)
|
|
||||||
add_line(win, text, attr=attr)
|
add_line(win, text, attr=attr)
|
||||||
|
|
||||||
add_line(win, u' {score} {created} '.format(**data))
|
add_line(win, u' {score} {created} '.format(**data))
|
||||||
|
|
||||||
if data['gold']:
|
if data['gold']:
|
||||||
@@ -247,13 +241,7 @@ class SubmissionPage(BasePage):
|
|||||||
|
|
||||||
row = len(data['split_title']) + len(split_text) + 3
|
row = len(data['split_title']) + len(split_text) + 3
|
||||||
add_line(win, u'{score} '.format(**data), row, 1)
|
add_line(win, u'{score} '.format(**data), row, 1)
|
||||||
|
text, attr = get_arrow(data['likes'])
|
||||||
if data['likes'] is None:
|
|
||||||
text, attr = BULLET, curses.A_BOLD
|
|
||||||
elif data['likes']:
|
|
||||||
text, attr = UARROW, curses.A_BOLD | Color.GREEN
|
|
||||||
else:
|
|
||||||
text, attr = DARROW, curses.A_BOLD | Color.RED
|
|
||||||
add_line(win, text, attr=attr)
|
add_line(win, text, attr=attr)
|
||||||
add_line(win, u' {comments} '.format(**data))
|
add_line(win, u' {comments} '.format(**data))
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ from .submission import SubmissionPage
|
|||||||
from .content import SubredditContent
|
from .content import SubredditContent
|
||||||
from .helpers import open_browser, open_editor
|
from .helpers import open_browser, open_editor
|
||||||
from .docs import SUBMISSION_FILE
|
from .docs import SUBMISSION_FILE
|
||||||
from .curses_helpers import (BULLET, UARROW, DARROW, GOLD, Color, add_line,
|
from .curses_helpers import (GOLD, Color, LoadScreen, add_line, get_arrow,
|
||||||
LoadScreen, show_notification, prompt_input)
|
show_notification, prompt_input)
|
||||||
|
|
||||||
__all__ = ['opened_links', 'SubredditController', 'SubredditPage']
|
__all__ = ['opened_links', 'SubredditController', 'SubredditPage']
|
||||||
|
|
||||||
@@ -175,13 +175,7 @@ class SubredditPage(BasePage):
|
|||||||
row = n_title + offset + 1
|
row = n_title + offset + 1
|
||||||
if row in valid_rows:
|
if row in valid_rows:
|
||||||
add_line(win, u'{score} '.format(**data), row, 1)
|
add_line(win, u'{score} '.format(**data), row, 1)
|
||||||
|
text, attr = get_arrow(data['likes'])
|
||||||
if data['likes'] is None:
|
|
||||||
text, attr = BULLET, curses.A_BOLD
|
|
||||||
elif data['likes']:
|
|
||||||
text, attr = UARROW, curses.A_BOLD | Color.GREEN
|
|
||||||
else:
|
|
||||||
text, attr = DARROW, curses.A_BOLD | Color.RED
|
|
||||||
add_line(win, text, attr=attr)
|
add_line(win, text, attr=attr)
|
||||||
add_line(win, u' {created} {comments} '.format(**data))
|
add_line(win, u' {created} {comments} '.format(**data))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user