@@ -12,7 +12,7 @@ from . import docs
|
|||||||
from .config import Config, copy_default_config
|
from .config import Config, copy_default_config
|
||||||
from .oauth import OAuthHelper
|
from .oauth import OAuthHelper
|
||||||
from .terminal import Terminal
|
from .terminal import Terminal
|
||||||
from .objects import curses_session
|
from .objects import curses_session, Color
|
||||||
from .subreddit import SubredditPage
|
from .subreddit import SubredditPage
|
||||||
from .exceptions import ConfigError
|
from .exceptions import ConfigError
|
||||||
from .__version__ import __version__
|
from .__version__ import __version__
|
||||||
@@ -83,6 +83,11 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with curses_session() as stdscr:
|
with curses_session() as stdscr:
|
||||||
|
|
||||||
|
# Initialize global color-pairs with curses
|
||||||
|
if not config['monochrome']:
|
||||||
|
Color.init()
|
||||||
|
|
||||||
term = Terminal(stdscr, config['ascii'])
|
term = Terminal(stdscr, config['ascii'])
|
||||||
with term.loader('Initializing', catch_exception=False):
|
with term.loader('Initializing', catch_exception=False):
|
||||||
reddit = praw.Reddit(user_agent=user_agent,
|
reddit = praw.Reddit(user_agent=user_agent,
|
||||||
|
|||||||
@@ -33,19 +33,22 @@ def build_parser():
|
|||||||
'-V', '--version', action='version', version='rtv '+__version__)
|
'-V', '--version', action='version', version='rtv '+__version__)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-s', dest='subreddit',
|
'-s', dest='subreddit',
|
||||||
help='name of the subreddit that will be opened on start')
|
help='Name of the subreddit that will be opened on start')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-l', dest='link',
|
'-l', dest='link',
|
||||||
help='full URL of a submission that will be opened on start')
|
help='Full URL of a submission that will be opened on start')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--log', metavar='FILE', action='store',
|
'--log', metavar='FILE', action='store',
|
||||||
help='log HTTP requests to the given file')
|
help='Log HTTP requests to the given file')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--config', metavar='FILE', action='store',
|
'--config', metavar='FILE', action='store',
|
||||||
help='Load configuration settings from the given file')
|
help='Load configuration settings from the given file')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--ascii', action='store_const', const=True,
|
'--ascii', action='store_const', const=True,
|
||||||
help='enable ascii-only mode')
|
help='Enable ascii-only mode')
|
||||||
|
parser.add_argument(
|
||||||
|
'--monochrome', action='store_const', const=True,
|
||||||
|
help='Disable color')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--non-persistent', dest='persistent', action='store_const',
|
'--non-persistent', dest='persistent', action='store_const',
|
||||||
const=False,
|
const=False,
|
||||||
@@ -79,6 +82,7 @@ def copy_default_config(filename=CONFIG):
|
|||||||
|
|
||||||
print('Copying default settings to %s' % filename)
|
print('Copying default settings to %s' % filename)
|
||||||
shutil.copy(DEFAULT_CONFIG, filename)
|
shutil.copy(DEFAULT_CONFIG, filename)
|
||||||
|
os.chmod(filename, 0o664)
|
||||||
|
|
||||||
|
|
||||||
class OrderedSet(object):
|
class OrderedSet(object):
|
||||||
@@ -208,6 +212,7 @@ class Config(object):
|
|||||||
|
|
||||||
params = {
|
params = {
|
||||||
'ascii': partial(config.getboolean, 'rtv'),
|
'ascii': partial(config.getboolean, 'rtv'),
|
||||||
|
'monochrome': partial(config.getboolean, 'rtv'),
|
||||||
'clear_auth': partial(config.getboolean, 'rtv'),
|
'clear_auth': partial(config.getboolean, 'rtv'),
|
||||||
'persistent': partial(config.getboolean, 'rtv'),
|
'persistent': partial(config.getboolean, 'rtv'),
|
||||||
'history_size': partial(config.getint, 'rtv'),
|
'history_size': partial(config.getint, 'rtv'),
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ def curses_session():
|
|||||||
# Hide the blinking cursor
|
# Hide the blinking cursor
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
|
|
||||||
Color.init()
|
# Assign the terminal's default (background) color to code -1
|
||||||
|
curses.use_default_colors()
|
||||||
|
|
||||||
yield stdscr
|
yield stdscr
|
||||||
|
|
||||||
@@ -254,7 +255,6 @@ class LoadScreen(object):
|
|||||||
|
|
||||||
|
|
||||||
class Color(object):
|
class Color(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Color attributes for curses.
|
Color attributes for curses.
|
||||||
"""
|
"""
|
||||||
@@ -286,9 +286,6 @@ class Color(object):
|
|||||||
curses color pairs can be accessed directly through class attributes.
|
curses color pairs can be accessed directly through class attributes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Assign the terminal's default (background) color to code -1
|
|
||||||
curses.use_default_colors()
|
|
||||||
|
|
||||||
for index, (attr, code) in enumerate(cls._colors.items(), start=1):
|
for index, (attr, code) in enumerate(cls._colors.items(), start=1):
|
||||||
curses.init_pair(index, code[0], code[1])
|
curses.init_pair(index, code[0], code[1])
|
||||||
setattr(cls, attr, curses.color_pair(index))
|
setattr(cls, attr, curses.color_pair(index))
|
||||||
|
|||||||
@@ -13,6 +13,9 @@
|
|||||||
; This may be necessary for compatibility with some terminal browsers.
|
; This may be necessary for compatibility with some terminal browsers.
|
||||||
ascii = False
|
ascii = False
|
||||||
|
|
||||||
|
; Turn on monochrome mode to disable color.
|
||||||
|
monochrome = False
|
||||||
|
|
||||||
; Enable debugging by logging all HTTP requests and errors to the given file.
|
; Enable debugging by logging all HTTP requests and errors to the given file.
|
||||||
;log = /tmp/rtv.log
|
;log = /tmp/rtv.log
|
||||||
|
|
||||||
|
|||||||
@@ -53,9 +53,10 @@ def test_config_get_args():
|
|||||||
'--log', 'logfile.log',
|
'--log', 'logfile.log',
|
||||||
'--config', 'configfile.cfg',
|
'--config', 'configfile.cfg',
|
||||||
'--ascii',
|
'--ascii',
|
||||||
|
'--monochrome',
|
||||||
'--non-persistent',
|
'--non-persistent',
|
||||||
'--clear-auth',
|
'--clear-auth',
|
||||||
'--copy-config']
|
'--copy-config',]
|
||||||
|
|
||||||
with mock.patch('sys.argv', ['rtv']):
|
with mock.patch('sys.argv', ['rtv']):
|
||||||
config_dict = Config.get_args()
|
config_dict = Config.get_args()
|
||||||
@@ -67,6 +68,7 @@ def test_config_get_args():
|
|||||||
|
|
||||||
config = Config(**config_dict)
|
config = Config(**config_dict)
|
||||||
assert config['ascii'] is True
|
assert config['ascii'] is True
|
||||||
|
assert config['monochrome'] is True
|
||||||
assert config['subreddit'] == 'cfb'
|
assert config['subreddit'] == 'cfb'
|
||||||
assert config['log'] == 'logfile.log'
|
assert config['log'] == 'logfile.log'
|
||||||
assert config['ascii'] is True
|
assert config['ascii'] is True
|
||||||
@@ -82,6 +84,7 @@ def test_config_from_file():
|
|||||||
|
|
||||||
args = {
|
args = {
|
||||||
'ascii': True,
|
'ascii': True,
|
||||||
|
'monochrome': True,
|
||||||
'persistent': False,
|
'persistent': False,
|
||||||
'clear_auth': True,
|
'clear_auth': True,
|
||||||
'log': 'logfile.log',
|
'log': 'logfile.log',
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ def test_objects_color(stdscr):
|
|||||||
assert getattr(Color, color) == curses.A_NORMAL
|
assert getattr(Color, color) == curses.A_NORMAL
|
||||||
|
|
||||||
Color.init()
|
Color.init()
|
||||||
assert curses.use_default_colors.called
|
|
||||||
|
|
||||||
# Check that all colors are populated
|
# Check that all colors are populated
|
||||||
for color in colors:
|
for color in colors:
|
||||||
@@ -182,6 +181,7 @@ def test_objects_curses_session(stdscr):
|
|||||||
pass
|
pass
|
||||||
assert curses.initscr.called
|
assert curses.initscr.called
|
||||||
assert curses.endwin.called
|
assert curses.endwin.called
|
||||||
|
assert curses.use_default_colors.called
|
||||||
curses.initscr.reset_mock()
|
curses.initscr.reset_mock()
|
||||||
curses.endwin.reset_mock()
|
curses.endwin.reset_mock()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user