Remove escape codes from output to stop garbling the interface.

This commit is contained in:
Andrew Hamilton 2016-10-03 16:06:50 +02:00
parent 9dddc8ce8c
commit 99fa974b56
4 changed files with 15 additions and 9 deletions

View file

@ -1,3 +1,3 @@
Cover Page
#

View file

@ -1,7 +1,7 @@
===SORRY!===
#[31m===#[0mSORRY!#[31m===#[0m
Two terms in a row across lines (missing semicolon or comma?)
at /tmp/vigil/golden-files/./input/perl6.p6:30
------> say 'Hello from Perl 6!'⏏<EOL>
------> #[32msay 'Hello from Perl 6!'#[33m⏏#[31m<EOL>#[0m
expecting any of:
infix
infix stopper
@ -12,5 +12,5 @@ at /tmp/vigil/golden-files/./input/perl6.p6:30
Other potential difficulties:
Useless declaration of a has-scoped method in mainline (did you mean 'my regex http-verb'?)
at /tmp/vigil/golden-files/./input/perl6.p6:11
------> regex ⏏http-verb {
------> #[32mregex #[33m⏏#[31mhttp-verb {#[0m

View file

@ -1,7 +1,7 @@
===SORRY!===
#[31m===#[0mSORRY!#[31m===#[0m
Two terms in a row across lines (missing semicolon or comma?)
at /tmp/vigil/golden-files/./input/perl6.pl:30
------> say 'Hello from Perl 6!'⏏<EOL>
------> #[32msay 'Hello from Perl 6!'#[33m⏏#[31m<EOL>#[0m
expecting any of:
infix
infix stopper
@ -12,5 +12,5 @@ at /tmp/vigil/golden-files/./input/perl6.pl:30
Other potential difficulties:
Useless declaration of a has-scoped method in mainline (did you mean 'my regex http-verb'?)
at /tmp/vigil/golden-files/./input/perl6.pl:11
------> regex ⏏http-verb {
------> #[32mregex #[33m⏏#[31mhttp-verb {#[0m

View file

@ -18,6 +18,7 @@ import os.path
import pickle
import pwd
import stat
import string
import subprocess
import tempfile
import time
@ -84,9 +85,14 @@ _LS_COLOR_CODES = get_ls_color_codes()
TIMEOUT = 60
def _printable(text):
return "".join(char if ord(char) > 31 or char in ["\n", "\t"] else "#"
for char in text)
def _fix_input(input_):
input_str = input_.decode("utf-8") if isinstance(input_, bytes) else input_
return input_str.expandtabs(tabsize=4)
return _printable(input_str).expandtabs(tabsize=4)
def _do_command(command, timeout=None, **kwargs):
@ -248,7 +254,7 @@ def contents(path):
root, ext = splitext(path)
if ext == "":
with open(path) as file_:
return Status.normal, fill3.Text(file_.read())
return Status.normal, fill3.Text(_fix_input(file_.read()))
else:
return pygments_(path)
contents.dependencies = {"python3-pygments"}