diff --git a/tools.py b/tools.py index 095218e..bd98ce2 100644 --- a/tools.py +++ b/tools.py @@ -135,7 +135,7 @@ def _syntax_highlight(text, lexer, style): def _char_style_for_token_type(token_type, default_bg_color): token_style = style.style_for_token(token_type) - fg_color = (None if token_style["color"] is None + fg_color = (termstr.Color.black if token_style["color"] is None else _parse_rgb(token_style["color"])) bg_color = (default_bg_color if token_style["bgcolor"] is None else _parse_rgb(token_style["bgcolor"])) @@ -153,8 +153,8 @@ def _syntax_highlight(text, lexer, style): def _syntax_highlight_using_path(text, path): lexer = pygments.lexers.get_lexer_for_filename(path, text) - native_style = pygments.styles.get_style_by_name("native") - return _syntax_highlight(text, lexer, native_style) + style = pygments.styles.get_style_by_name(os.environ["PYGMENT_STYLE"]) + return _syntax_highlight(text, lexer, style) def pygments_(path): @@ -770,7 +770,7 @@ def run_tool_no_error(path, tool): except: status, result = Status.error, _syntax_highlight( traceback.format_exc(), pygments.lexers.PythonTracebackLexer(), - pygments.styles.get_style_by_name("native")) + pygments.styles.get_style_by_name(os.environ["PYGMENT_STYLE"])) return status, result diff --git a/vigil b/vigil index 8a8a915..a1e707c 100755 --- a/vigil +++ b/vigil @@ -34,6 +34,7 @@ import sys import time import docopt +import pygments.styles import pyinotify import fill3 @@ -59,6 +60,8 @@ Options: By default it is twice the number of cpus. -e "COMMAND", --editor="COMMAND" The command used to start the editor, in the *edit command. It may contain options. + -t THEME, --theme=THEME The pygment theme used for syntax + highlighting. Defaults to "native". """ @@ -916,9 +919,12 @@ def save_state(pickle_path, summary, screen, log): def main(root_path, loop, worker_count=None, is_sandboxed=True, - editor_command=None, is_being_tested=False): + editor_command=None, theme=None, is_being_tested=False): if worker_count is None: worker_count = multiprocessing.cpu_count() + if theme == None: + theme = "native" + os.environ["PYGMENT_STYLE"] = theme pickle_path = os.path.join(tools.CACHE_PATH, "summary.pickle") jobs_added_event = asyncio.Event() appearance_changed_event = asyncio.Event() @@ -1003,16 +1009,23 @@ def check_arguments(): print("--sandbox argument must be 'on' or 'off'") sys.exit(1) is_sandboxed = arguments["--sandbox"] in ["on", None] + themes = list(pygments.styles.get_all_styles()) + if arguments["--theme"] not in themes: + print("--theme must be one of: %s" % " ".join(themes)) + sys.exit(1) editor_command = arguments["--editor"] or os.environ.get("EDITOR", None)\ or os.environ.get("VISUAL", None) - return root_path, worker_count, is_sandboxed, editor_command + return root_path, worker_count, is_sandboxed, editor_command, \ + arguments["--theme"] if __name__ == "__main__": - root_path, worker_count, is_sandboxed, editor_command = check_arguments() + root_path, worker_count, is_sandboxed, editor_command, theme = \ + check_arguments() with terminal.console_title("vigil: " + os.path.basename(root_path)): manage_cache(root_path) with chdir(root_path): # FIX: Don't change directory if possible. loop = asyncio.get_event_loop() - main(root_path, loop, worker_count, is_sandboxed, editor_command) + main(root_path, loop, worker_count, is_sandboxed, editor_command, + theme) os._exit(0)