coding style: Redirect stdout to simplify multiple prints

This commit is contained in:
Andrew Hamilton 2025-06-10 13:39:24 +10:00
parent 9962068019
commit 4c68e226bf

View file

@ -1122,18 +1122,18 @@ def print_tool_info():
output_file = pager_process.stdin output_file = pager_process.stdin
else: else:
output_file = sys.stdout output_file = sys.stdout
for tool in sorted(tools.tools_all(), key=lambda t: t.__name__): with contextlib.redirect_stdout(output_file):
print(termstr.TermStr(tool.__name__, is_bold=True) if tools.is_tool_available(tool) for tool in sorted(tools.tools_all(), key=lambda t: t.__name__):
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)
, file=output_file) else termstr.TermStr(tool.__name__, fg_color=termstr.Color.red) + " (not available)")
if hasattr(tool, "command"): if hasattr(tool, "command"):
print(f"command: {tool.command} foo.{extensions[0]}", file=output_file) print(f"command: {tool.command} foo.{extensions[0]}")
else: else:
print("function:", "eris.tools." + tool.__name__, file=output_file) print("function:", "eris.tools." + tool.__name__)
print("url:", tool.url, file=output_file) print("url:", tool.url)
extensions = list(extensions_for_tool.get(tool, {"*"})) extensions = list(extensions_for_tool.get(tool, {"*"}))
print("extensions:", ", ".join(extensions), file=output_file) print("extensions:", ", ".join(extensions))
print("", file=output_file) print("")
if pager_process is not None: if pager_process is not None:
output_file.close() output_file.close()
pager_process.wait() pager_process.wait()