tools: Enable color in pylint.
This commit is contained in:
parent
5949a82c2d
commit
cfa591976c
4 changed files with 37 additions and 28 deletions
|
|
@ -166,33 +166,38 @@ class TermStr(collections.UserString):
|
||||||
is_bold, is_italic, is_underlined = False, False, False
|
is_bold, is_italic, is_underlined = False, False, False
|
||||||
result_parts = [parts[0]]
|
result_parts = [parts[0]]
|
||||||
for part in parts[1:]:
|
for part in parts[1:]:
|
||||||
try:
|
end_index = part.index("m")
|
||||||
end_index = part.index("m")
|
codes = part[1:end_index].split(";")
|
||||||
except ValueError:
|
previous_code = None
|
||||||
end_index = 0
|
for index, code in enumerate(codes):
|
||||||
if part[:2] == terminal.normal or part[:3] == "[0m": # Normal
|
if code in ["", "0"]: # Normal
|
||||||
is_bold, is_italic, is_underlined = False, False, False
|
is_bold, is_italic, is_underlined = False, False, False
|
||||||
fg_color, bg_color = None, None
|
fg_color, bg_color = None, None
|
||||||
elif part[:3] == terminal.bold:
|
elif code == "1": # bold
|
||||||
is_bold = True
|
is_bold = True
|
||||||
elif part[:3] == terminal.italic:
|
elif code == "3": # italic
|
||||||
is_italic = True
|
is_italic = True
|
||||||
elif part[:3] == terminal.underline:
|
elif code == "4": # underline
|
||||||
is_underlined = True
|
is_underlined = True
|
||||||
elif end_index == 3 and part.startswith("[3"): # 8 foreground color
|
elif len(code) == 2 and code.startswith("3"): # 8 fg color
|
||||||
fg_color = int(part[2])
|
fg_color = int(code[1])
|
||||||
elif end_index == 3 and part.startswith("[4"): # 8 background color
|
elif len(code) == 2 and code.startswith("4"): # 8 bg color
|
||||||
bg_color = int(part[2])
|
bg_color = int(code[1])
|
||||||
elif part[:6] == "[38;5;": # simple foreground color
|
elif code == "5" and previous_code == "38": # simple fg color
|
||||||
fg_color = int(part[6:end_index])
|
fg_color = int(codes[index+1])
|
||||||
elif part[:6] == "[48;5;": # simple background color
|
codes[index+1:index+2] = []
|
||||||
bg_color = int(part[6:end_index])
|
elif code == "5" and previous_code == "48": # simple bg color
|
||||||
elif part[:6] == "[38;2;": # rgb foreground color
|
bg_color = int(codes[index+1])
|
||||||
fg_color = tuple(int(component)
|
codes[index+1:index+2] = []
|
||||||
for component in part[6:end_index].split(";"))
|
elif code == "2" and previous_code == "38": # rgb fg color
|
||||||
elif part[:6] == "[48;2;": # rgb background color
|
fg_color = tuple(int(component)
|
||||||
bg_color = tuple(int(component)
|
for component in codes[index+1:index+4])
|
||||||
for component in part[6:end_index].split(";"))
|
codes[index+1:index+4] = []
|
||||||
|
elif code == "2" and previous_code == "48": # rgb bg color
|
||||||
|
bg_color = tuple(int(component)
|
||||||
|
for component in codes[index+1:index+4])
|
||||||
|
codes[index+1:index+4] = []
|
||||||
|
previous_code = code
|
||||||
result_parts.append(cls(part[end_index+1:],
|
result_parts.append(cls(part[end_index+1:],
|
||||||
CharStyle(fg_color, bg_color, is_bold,
|
CharStyle(fg_color, bg_color, is_bold,
|
||||||
is_italic, is_underlined)))
|
is_italic, is_underlined)))
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,8 @@ tools_for_extensions = [
|
||||||
[pylint]
|
[pylint]
|
||||||
dependencies = ["pip/pylint"]
|
dependencies = ["pip/pylint"]
|
||||||
url = "https://www.pylint.org/"
|
url = "https://www.pylint.org/"
|
||||||
command = "python3.7 -m pylint --errors-only"
|
command = "python3.7 -m pylint -f colorized --errors-only"
|
||||||
|
has_color = true
|
||||||
|
|
||||||
[python_modulefinder]
|
[python_modulefinder]
|
||||||
dependencies = []
|
dependencies = []
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
[m
|
||||||
|
|
@ -149,6 +149,8 @@ class TermStrTests(unittest.TestCase):
|
||||||
eris.terminal.ESC + "[0mbar"),
|
eris.terminal.ESC + "[0mbar"),
|
||||||
termstr.TermStr("foo").bg_color(5) +
|
termstr.TermStr("foo").bg_color(5) +
|
||||||
termstr.TermStr("bar"))
|
termstr.TermStr("bar"))
|
||||||
|
self.assertEqual(TermStr.from_term(eris.terminal.ESC + "[1;3mfoo"),
|
||||||
|
termstr.TermStr("foo").bold().italic())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue