Show italic file types correctly.

- Some file types have italic lscolors style, e.g. pem files.
- Using TermStr.from_term to parse lscodes now it exists.
This commit is contained in:
Andrew Hamilton 2021-11-15 09:31:31 +10:00
parent 06fc1be36d
commit 28b2c9bae9

View file

@ -739,24 +739,10 @@ def run_tool_no_error(path, tool):
pygments.styles.get_style_by_name(os.environ["PYGMENT_STYLE"])) pygments.styles.get_style_by_name(os.environ["PYGMENT_STYLE"]))
def _convert_lscolor_code_to_charstyle(lscolor_code):
parts = lscolor_code.split(";")
if len(parts) == 1:
is_bold = parts[0] == "1"
fg_color = None
elif len(parts) == 2:
is_bold = False
fg_color = int(parts[1])
else:
is_bold = len(parts) == 4 and parts[3] == "1"
fg_color = int(parts[2])
return termstr.CharStyle(fg_color=fg_color, is_bold=is_bold)
def _charstyle_of_path(path): def _charstyle_of_path(path):
color_code = lscolors.color_code_for_path(path, _LS_COLOR_CODES) color_code = lscolors.color_code_for_path(path, _LS_COLOR_CODES)
return (termstr.CharStyle() if color_code is None else term_text = termstr.ESC + "[" + color_code + "m-"
_convert_lscolor_code_to_charstyle(color_code)) return termstr.TermStr.from_term(term_text).style[0]
@functools.lru_cache(maxsize=100) @functools.lru_cache(maxsize=100)