Added a cmdline option for the syntax highlighting style.
This commit is contained in:
parent
b017c4865e
commit
294d3f8c96
2 changed files with 21 additions and 8 deletions
8
tools.py
8
tools.py
|
|
@ -135,7 +135,7 @@ def _syntax_highlight(text, lexer, style):
|
||||||
|
|
||||||
def _char_style_for_token_type(token_type, default_bg_color):
|
def _char_style_for_token_type(token_type, default_bg_color):
|
||||||
token_style = style.style_for_token(token_type)
|
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"]))
|
else _parse_rgb(token_style["color"]))
|
||||||
bg_color = (default_bg_color if token_style["bgcolor"] is None
|
bg_color = (default_bg_color if token_style["bgcolor"] is None
|
||||||
else _parse_rgb(token_style["bgcolor"]))
|
else _parse_rgb(token_style["bgcolor"]))
|
||||||
|
|
@ -153,8 +153,8 @@ def _syntax_highlight(text, lexer, style):
|
||||||
|
|
||||||
def _syntax_highlight_using_path(text, path):
|
def _syntax_highlight_using_path(text, path):
|
||||||
lexer = pygments.lexers.get_lexer_for_filename(path, text)
|
lexer = pygments.lexers.get_lexer_for_filename(path, text)
|
||||||
native_style = pygments.styles.get_style_by_name("native")
|
style = pygments.styles.get_style_by_name(os.environ["PYGMENT_STYLE"])
|
||||||
return _syntax_highlight(text, lexer, native_style)
|
return _syntax_highlight(text, lexer, style)
|
||||||
|
|
||||||
|
|
||||||
def pygments_(path):
|
def pygments_(path):
|
||||||
|
|
@ -770,7 +770,7 @@ def run_tool_no_error(path, tool):
|
||||||
except:
|
except:
|
||||||
status, result = Status.error, _syntax_highlight(
|
status, result = Status.error, _syntax_highlight(
|
||||||
traceback.format_exc(), pygments.lexers.PythonTracebackLexer(),
|
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
|
return status, result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
21
vigil
21
vigil
|
|
@ -34,6 +34,7 @@ import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import docopt
|
import docopt
|
||||||
|
import pygments.styles
|
||||||
import pyinotify
|
import pyinotify
|
||||||
|
|
||||||
import fill3
|
import fill3
|
||||||
|
|
@ -59,6 +60,8 @@ Options:
|
||||||
By default it is twice the number of cpus.
|
By default it is twice the number of cpus.
|
||||||
-e "COMMAND", --editor="COMMAND" The command used to start the editor, in
|
-e "COMMAND", --editor="COMMAND" The command used to start the editor, in
|
||||||
the *edit command. It may contain options.
|
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,
|
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:
|
if worker_count is None:
|
||||||
worker_count = multiprocessing.cpu_count()
|
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")
|
pickle_path = os.path.join(tools.CACHE_PATH, "summary.pickle")
|
||||||
jobs_added_event = asyncio.Event()
|
jobs_added_event = asyncio.Event()
|
||||||
appearance_changed_event = asyncio.Event()
|
appearance_changed_event = asyncio.Event()
|
||||||
|
|
@ -1003,16 +1009,23 @@ def check_arguments():
|
||||||
print("--sandbox argument must be 'on' or 'off'")
|
print("--sandbox argument must be 'on' or 'off'")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
is_sandboxed = arguments["--sandbox"] in ["on", None]
|
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)\
|
editor_command = arguments["--editor"] or os.environ.get("EDITOR", None)\
|
||||||
or os.environ.get("VISUAL", 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__":
|
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)):
|
with terminal.console_title("vigil: " + os.path.basename(root_path)):
|
||||||
manage_cache(root_path)
|
manage_cache(root_path)
|
||||||
with chdir(root_path): # FIX: Don't change directory if possible.
|
with chdir(root_path): # FIX: Don't change directory if possible.
|
||||||
loop = asyncio.get_event_loop()
|
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)
|
os._exit(0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue