Added a tool 'view' that shows the contents of files without extensions.

Its currently failing with binary files.
This commit is contained in:
Andrew Hamilton 2016-01-24 21:06:17 +00:00
parent 40b2460038
commit e9bc1c73c1
2 changed files with 14 additions and 5 deletions

View file

@ -126,9 +126,8 @@ def pygments_(path):
try: try:
source_widget = _syntax_highlight_code(fix_input(text), path) source_widget = _syntax_highlight_code(fix_input(text), path)
except pygments.util.ClassNotFound: except pygments.util.ClassNotFound:
return Status.not_applicable, fill3.Text("No lexer found") return Status.normal, fill3.Text(text)
return Status.normal, source_widget return Status.normal, source_widget
pygments_.dependencies = ["python3-pygments"]
def linguist(path): def linguist(path):
@ -206,11 +205,21 @@ def metadata(path):
text.append("\n") text.append("\n")
else: else:
name, value = line name, value = line
text.append("%-15s: %s\n" % (name, "".join(value))) text.append("%-15s %s\n" % (name + ":", "".join(value)))
return (Status.normal, fill3.Text("".join(text))) return (Status.normal, fill3.Text("".join(text)))
metadata.dependencies = {"file", "coreutils"} metadata.dependencies = {"file", "coreutils"}
def view(path):
root, ext = splitext(path)
if ext == "":
with open(path) as file_:
return Status.normal, fill3.Text(file_.read())
else:
return pygments_(path)
view.dependencies = {"python3-pygments"}
def _is_python_syntax_correct(path, python_version): def _is_python_syntax_correct(path, python_version):
if python_version == "python": if python_version == "python":
stdin, stdout, returncode = _do_command( stdin, stdout, returncode = _do_command(
@ -553,7 +562,7 @@ flog.dependencies = set()
def generic_tools(): def generic_tools():
return [metadata, pygments_] return [metadata, view]
def tools_for_extension(): def tools_for_extension():

2
vigil
View file

@ -818,7 +818,7 @@ class Runner:
with contextlib.suppress(ValueError): # Process was terminated with contextlib.suppress(ValueError): # Process was terminated
self.result.run(log, appearance_changed_event, self.worker) self.result.run(log, appearance_changed_event, self.worker)
summary.completed_total += 1 summary.completed_total += 1
if self.is_being_tested: if self.is_being_tested and self.result.tool == tools.metadata:
os.kill(os.getpid(), signal.SIGINT) os.kill(os.getpid(), signal.SIGINT)
jobs_added_event.clear() jobs_added_event.clear()