tools: Fix screen corruption from TextWidgets containing line breaks.

This commit is contained in:
Andrew Hamilton 2018-07-24 21:44:13 +10:00
parent 9b47e07cf6
commit b41c86afac
19 changed files with 28 additions and 41 deletions

View file

@ -1,2 +1 @@
(Bdef(B (Bhi(B():
(B
(Bdef(B (Bhi(B():(B

View file

@ -1,2 +1 @@
(Bdef(B (Bhi(B():
(B
(Bdef(B (Bhi(B():(B

View file

@ -1,2 +1 @@
(B
(B

View file

@ -341,7 +341,7 @@ class Text:
if len(lines) == 0:
self.text = []
elif len(lines) == 1:
self.text = [text]
self.text = [lines[0]]
else:
max_width = max(len(line) for line in lines)
height = len(lines)

View file

@ -157,21 +157,6 @@ def _syntax_highlight_using_path(text, path):
return _syntax_highlight(text, lexer, style)
def pygments_(path):
with open(path) as file_:
try:
text = file_.read()
except UnicodeDecodeError:
return Status.not_applicable, fill3.Text("Not unicode")
else:
try:
source_widget = _syntax_highlight_using_path(_fix_input(text),
path)
except pygments.util.ClassNotFound:
return Status.normal, fill3.Text(text)
return Status.normal, source_widget
def linguist(path):
# Dep: ruby?, ruby-dev, libicu-dev, cmake, "gem install github-linguist"
return _run_command(["linguist", path], Status.normal)
@ -252,12 +237,17 @@ def metadata(path):
@deps(deps={"python3-pygments"}, url="python3-pygments")
def contents(path):
root, ext = splitext(path)
if ext == "":
with open(path) as file_:
return Status.normal, fill3.Text(_fix_input(file_.read()))
else:
return pygments_(path)
try:
text = file_.read()
except UnicodeDecodeError:
return Status.not_applicable, fill3.Text("Not unicode")
text = _fix_input(text)
try:
text_widget = _syntax_highlight_using_path(text, path)
except pygments.util.ClassNotFound:
text_widget = fill3.Text(text)
return Status.normal, text_widget
def _is_python_syntax_correct(path, python_version):