Add monochrome option, chmod 664 when copying config.

This commit is contained in:
Michael Lazar
2016-04-12 15:56:09 -07:00
parent 95d37ecf55
commit b72b7965c1
6 changed files with 21 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ from . import docs
from .config import Config, copy_default_config
from .oauth import OAuthHelper
from .terminal import Terminal
from .objects import curses_session
from .objects import curses_session, Color
from .subreddit import SubredditPage
from .exceptions import ConfigError
from .__version__ import __version__
@@ -83,6 +83,11 @@ def main():
try:
with curses_session() as stdscr:
# Initialize global color-pairs with curses
if not config['monochrome']:
Color.init()
term = Terminal(stdscr, config['ascii'])
with term.loader('Initializing', catch_exception=False):
reddit = praw.Reddit(user_agent=user_agent,

View File

@@ -46,6 +46,9 @@ def build_parser():
parser.add_argument(
'--ascii', action='store_const', const=True,
help='enable ascii-only mode')
parser.add_argument(
'--monochrome', action='store_const', const=True,
help='enable monochrome mode and force text to black & white')
parser.add_argument(
'--non-persistent', dest='persistent', action='store_const',
const=False,
@@ -79,6 +82,7 @@ def copy_default_config(filename=CONFIG):
print('Copying default settings to %s' % filename)
shutil.copy(DEFAULT_CONFIG, filename)
os.chmod(filename, 0o664)
class OrderedSet(object):
@@ -208,6 +212,7 @@ class Config(object):
params = {
'ascii': partial(config.getboolean, 'rtv'),
'monochrome': partial(config.getboolean, 'rtv'),
'clear_auth': partial(config.getboolean, 'rtv'),
'persistent': partial(config.getboolean, 'rtv'),
'history_size': partial(config.getint, 'rtv'),

View File

@@ -62,7 +62,8 @@ def curses_session():
# Hide the blinking cursor
curses.curs_set(0)
Color.init()
# Assign the terminal's default (background) color to code -1
curses.use_default_colors()
yield stdscr
@@ -254,7 +255,6 @@ class LoadScreen(object):
class Color(object):
"""
Color attributes for curses.
"""
@@ -286,9 +286,6 @@ class Color(object):
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):
curses.init_pair(index, code[0], code[1])
setattr(cls, attr, curses.color_pair(index))

View File

@@ -13,6 +13,9 @@
; This may be necessary for compatibility with some terminal browsers.
ascii = False
; Turn on monochrome mode to force text to black and white.
monochrome = False
; Enable debugging by logging all HTTP requests and errors to the given file.
;log = /tmp/rtv.log

View File

@@ -53,9 +53,10 @@ def test_config_get_args():
'--log', 'logfile.log',
'--config', 'configfile.cfg',
'--ascii',
'--monochrome',
'--non-persistent',
'--clear-auth',
'--copy-config']
'--copy-config',]
with mock.patch('sys.argv', ['rtv']):
config_dict = Config.get_args()
@@ -67,6 +68,7 @@ def test_config_get_args():
config = Config(**config_dict)
assert config['ascii'] is True
assert config['monochrome'] is True
assert config['subreddit'] == 'cfb'
assert config['log'] == 'logfile.log'
assert config['ascii'] is True
@@ -82,6 +84,7 @@ def test_config_from_file():
args = {
'ascii': True,
'monochrome': True,
'persistent': False,
'clear_auth': True,
'log': 'logfile.log',

View File

@@ -168,7 +168,6 @@ def test_objects_color(stdscr):
assert getattr(Color, color) == curses.A_NORMAL
Color.init()
assert curses.use_default_colors.called
# Check that all colors are populated
for color in colors:
@@ -182,6 +181,7 @@ def test_objects_curses_session(stdscr):
pass
assert curses.initscr.called
assert curses.endwin.called
assert curses.use_default_colors.called
curses.initscr.reset_mock()
curses.endwin.reset_mock()