Coding Style
- Use better termstr contructor.
This commit is contained in:
parent
54814ac0d3
commit
8efb2aaa69
6 changed files with 17 additions and 17 deletions
|
|
@ -815,7 +815,7 @@ class Screen:
|
|||
self._log.log_message([in_green("Refreshing all results of "), tool_name, in_green("…")])
|
||||
self._summary.refresh_tool(selection.tool)
|
||||
|
||||
_DIMMED_BORDER = [termstr.TermStr(part).fg_color(termstr.Color.grey_100)
|
||||
_DIMMED_BORDER = [termstr.TermStr(part, fg_color=termstr.Color.grey_100)
|
||||
for part in fill3.Border.THIN]
|
||||
|
||||
def _set_focus(self):
|
||||
|
|
@ -920,7 +920,7 @@ class Screen:
|
|||
@functools.cache
|
||||
def _get_partial_bar_chars(self, bar_transparency):
|
||||
bar_color = termstr.blend_color(termstr.Color.black, termstr.Color.white, bar_transparency)
|
||||
return [termstr.TermStr(char).fg_color(bar_color).bg_color(termstr.Color.black)
|
||||
return [termstr.TermStr(char, fg_color=bar_color, bg_color=termstr.Color.black)
|
||||
for char in fill3.ScrollBar._PARTIAL_CHARS[1]]
|
||||
|
||||
def _get_status_bar_appearance(self, width, progress_bar_size):
|
||||
|
|
@ -1113,8 +1113,8 @@ def print_tool_info():
|
|||
for tool in tools_:
|
||||
extensions_for_tool.setdefault(tool, {extension}).add(extension)
|
||||
for tool in sorted(tools.tools_all(), key=lambda t: t.__name__):
|
||||
print(termstr.TermStr(tool.__name__).bold() if tools.is_tool_available(tool)
|
||||
else termstr.TermStr(tool.__name__).fg_color(termstr.Color.red) + " (not available)")
|
||||
print(termstr.TermStr(tool.__name__, is_bold=True) if tools.is_tool_available(tool)
|
||||
else termstr.TermStr(tool.__name__, fg_color=termstr.Color.red) + " (not available)")
|
||||
if hasattr(tool, "command"):
|
||||
print(f"command: {tool.command} foo.{extensions[0]}")
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import termstr
|
|||
class TermDoc(pydoc.TextDoc):
|
||||
|
||||
def bold(self, text):
|
||||
return str(termstr.TermStr(text).bold())
|
||||
return str(termstr.TermStr(text, is_bold=True))
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ STATUS_MEANINGS = [(Status.ok, "Ok"), (Status.problem, "Problem"),
|
|||
(Status.error, "Error")]
|
||||
STATUS_TO_TERMSTR = {status: termstr.TermStr(" ", termstr.CharStyle(bg_color=color))
|
||||
for status, color in _STATUS_COLORS.items()}
|
||||
STATUS_TO_TERMSTR[Status.pending] = termstr.TermStr(".").fg_color(termstr.Color.grey_100)
|
||||
STATUS_TO_TERMSTR[Status.pending] = termstr.TermStr(".", fg_color=termstr.Color.grey_100)
|
||||
|
||||
|
||||
TIMEOUT = 60
|
||||
|
|
@ -130,7 +130,7 @@ def _syntax_highlight(text, lexer, style):
|
|||
text = termstr.join("", [termstr.TermStr(text, _char_style_for_token_type(
|
||||
token_type, default_bg_color, default_style))
|
||||
for token_type, text in pygments.lex(text, lexer)])
|
||||
text_widget = fill3.Text(text, pad_char=termstr.TermStr(" ").bg_color(default_bg_color))
|
||||
text_widget = fill3.Text(text, pad_char=termstr.TermStr(" ", bg_color=default_bg_color))
|
||||
return termstr.join("\n", text_widget.text)
|
||||
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ def metadata(path):
|
|||
|
||||
def detail(value, unit):
|
||||
result = f" ({value})" if unit is None else f" ({value} {unit})"
|
||||
return termstr.TermStr(result).fg_color(termstr.Color.grey_100)
|
||||
return termstr.TermStr(result, fg_color=termstr.Color.grey_100)
|
||||
is_symlink = "yes" if os.path.islink(path) else "no"
|
||||
stat_result = os.stat(path)
|
||||
permissions = stat.filemode(stat_result.st_mode)
|
||||
|
|
@ -197,7 +197,7 @@ def metadata(path):
|
|||
text.append("\n")
|
||||
else:
|
||||
name, value = line
|
||||
name = termstr.TermStr(name + ":").fg_color(termstr.Color.blue).ljust(16)
|
||||
name = termstr.TermStr(name + ":", fg_color=termstr.Color.blue).ljust(16)
|
||||
text.append(name + termstr.join("", value) + "\n")
|
||||
return Status.ok, termstr.join("", text)
|
||||
|
||||
|
|
@ -268,7 +268,7 @@ def mypy(path):
|
|||
|
||||
def _colorize_coverage_report(lines):
|
||||
line_color = {"> ": termstr.Color.green, "! ": termstr.Color.grey_150, " ": None}
|
||||
return termstr.join("", [termstr.TermStr(line).fg_color(line_color[line[:2]]) for line in lines])
|
||||
return termstr.join("", [termstr.TermStr(line, fg_color=line_color[line[:2]]) for line in lines])
|
||||
|
||||
|
||||
@deps(deps={"python3-coverage"}, url="https://coverage.readthedocs.io/")
|
||||
|
|
@ -329,7 +329,7 @@ def _get_mccabe_line_score(line):
|
|||
|
||||
def _colorize_mccabe(text):
|
||||
return termstr.join("", [
|
||||
termstr.TermStr(line).fg_color(termstr.Color.yellow)
|
||||
termstr.TermStr(line, fg_color=termstr.Color.yellow)
|
||||
if _get_mccabe_line_score(line) > 10 else line
|
||||
for line in text.splitlines(keepends=True)])
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ def make_listing_page(url_path):
|
|||
tool = getattr(tools, tool_name)
|
||||
tool_name_colored = tools.tool_name_colored(tool, path)
|
||||
header = fill3.appearance_as_html([lscolors.path_colored(path) + " - " + tool_name_colored,
|
||||
termstr.TermStr(" ").underline() * 100])
|
||||
termstr.TermStr(" " * 100, is_underlined=True)])
|
||||
body = fill3.appearance_as_html(result.appearance())
|
||||
return make_page(header + body, f"{path} - {tool_name}")
|
||||
|
||||
|
|
|
|||
|
|
@ -165,13 +165,13 @@ class ScrollBar:
|
|||
self.interval = interval
|
||||
bar_color = bar_color or ScrollBar.DEFAULT_BAR_COLOR
|
||||
background_color = background_color or ScrollBar.DEFAULT_BACKGROUND_COLOR
|
||||
self._bar_char = termstr.TermStr("█").fg_color(bar_color)
|
||||
self._background_char = termstr.TermStr(" ").bg_color(background_color)
|
||||
self._bar_char = termstr.TermStr("█", fg_color=bar_color)
|
||||
self._background_char = termstr.TermStr(" ", bg_color=background_color)
|
||||
if self._is_horizontal:
|
||||
bar_color, background_color = background_color, bar_color
|
||||
self._partial_chars = [
|
||||
(termstr.TermStr(char).fg_color(bar_color).bg_color(background_color),
|
||||
termstr.TermStr(char).fg_color(background_color).bg_color(bar_color))
|
||||
(termstr.TermStr(char, fg_color=bar_color, bg_color=background_color),
|
||||
termstr.TermStr(char, fg_color=background_color, bg_color=bar_color))
|
||||
for char in self._PARTIAL_CHARS[self._is_horizontal]]
|
||||
|
||||
def appearance_for(self, dimensions):
|
||||
|
|
|
|||
|
|
@ -164,6 +164,6 @@ def path_colored(path):
|
|||
dirname = dirname + os.path.sep
|
||||
dir_style = _charstyle_of_path(os.path.sep)
|
||||
parts = [termstr.TermStr(part, dir_style) for part in dirname.split(os.path.sep)]
|
||||
path_sep = termstr.TermStr(os.path.sep).fg_color(termstr.Color.grey_100)
|
||||
path_sep = termstr.TermStr(os.path.sep, fg_color=termstr.Color.grey_100)
|
||||
dir_name = termstr.join(path_sep, parts)
|
||||
return dir_name + termstr.TermStr(basename, char_style)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue