tools: Let color be specified in tools.toml.
This commit is contained in:
parent
9b5ad3332e
commit
4a1e109f07
3 changed files with 30 additions and 26 deletions
1
TODO
1
TODO
|
|
@ -1,6 +1,7 @@
|
|||
Todo
|
||||
- Publish on pypi.
|
||||
- Make a snap build work.
|
||||
- Colourise more tools: luacheck, gcc, perl6, shellcheck, elinks?
|
||||
|
||||
|
||||
Todo (tool related)
|
||||
|
|
|
|||
|
|
@ -109,10 +109,18 @@ def _do_command(command, **kwargs):
|
|||
|
||||
|
||||
def _run_command(command, success_status=None, error_status=None,
|
||||
timeout=None):
|
||||
has_color=False, timeout=None):
|
||||
success_status = Status.ok if success_status is None else success_status
|
||||
error_status = Status.problem if error_status is None else error_status
|
||||
stdout, stderr, returncode = _do_command(command, timeout=timeout)
|
||||
if has_color:
|
||||
process = subprocess.run(command, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, text=True,
|
||||
timeout=timeout)
|
||||
stdout, stderr, returncode = (termstr.TermStr.from_term(process.stdout),
|
||||
termstr.TermStr.from_term(process.stderr),
|
||||
process.returncode)
|
||||
else:
|
||||
stdout, stderr, returncode = _do_command(command, timeout=timeout)
|
||||
result_status = success_status if returncode == 0 else error_status
|
||||
return result_status, (stdout + stderr)
|
||||
|
||||
|
|
@ -400,28 +408,6 @@ def perltidy(path):
|
|||
return Status.normal, _syntax_highlight_using_path(stdout, path)
|
||||
|
||||
|
||||
@deps(deps={"git"}, url="https://git-scm.com/docs/git-blame",
|
||||
executables={"git"})
|
||||
def git_blame(path):
|
||||
process = subprocess.run([
|
||||
"git", "blame", "--show-stats", "--date=short", "--color-lines",
|
||||
"--color-by-age", path], text=True, capture_output=True)
|
||||
status = (Status.normal if process.returncode == 0
|
||||
else Status.not_applicable)
|
||||
return status, termstr.TermStr.from_term(process.stdout + process.stderr)
|
||||
|
||||
|
||||
@deps(deps={"git"}, url="https://git-scm.com/docs/git-log",
|
||||
executables={"git"})
|
||||
def git_log(path):
|
||||
process = subprocess.run(["git", "log", "--find-renames", "--follow",
|
||||
"--stat", "--color", path], text=True,
|
||||
capture_output=True)
|
||||
status = (Status.normal if process.returncode == 0
|
||||
else Status.not_applicable)
|
||||
return status, termstr.TermStr.from_term(process.stdout + process.stderr)
|
||||
|
||||
|
||||
@deps(deps={"tidy"}, url="tidy", executables={"tidy"})
|
||||
def html_syntax(path):
|
||||
# Maybe only show errors
|
||||
|
|
@ -487,7 +473,7 @@ def godoc(path):
|
|||
|
||||
|
||||
def make_tool_function(dependencies, command, url=None, success_status=None,
|
||||
error_status=None):
|
||||
error_status=None, has_color=False):
|
||||
if url is None:
|
||||
url = dependencies[0]
|
||||
command = command.split()
|
||||
|
|
@ -496,7 +482,8 @@ def make_tool_function(dependencies, command, url=None, success_status=None,
|
|||
error_status = None if error_status is None else Status[error_status]
|
||||
@deps(deps=set(dependencies), url=url, executables=executables)
|
||||
def func(path):
|
||||
return _run_command(command + [path], success_status, error_status)
|
||||
return _run_command(command + [path], success_status, error_status,
|
||||
has_color)
|
||||
return func
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,22 @@ tools_for_extensions = [
|
|||
url = "https://rakudo.org/"
|
||||
command = "perl6 -c"
|
||||
|
||||
[git_blame]
|
||||
dependencies = ["git"]
|
||||
url = "https://git-scm.com/docs/git-blame"
|
||||
command = "git blame --show-stats --date=short --color-lines --color-by-age"
|
||||
success_status = "normal"
|
||||
error_status = "not_applicable"
|
||||
has_color = true
|
||||
|
||||
[git_log]
|
||||
dependencies = ["git"]
|
||||
url = "https://git-scm.com/docs/git-log"
|
||||
command = "git log --find-renames --follow --stat --color"
|
||||
success_status = "normal"
|
||||
error_status = "not_applicable"
|
||||
has_color = true
|
||||
|
||||
[dis]
|
||||
dependencies = []
|
||||
url = "https://docs.python.org/3/library/dis.html"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue