From 4c68e226bf1b0fbd3095bfe2a3d9fd8ef0ff3cae Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Tue, 10 Jun 2025 13:39:24 +1000 Subject: [PATCH] coding style: Redirect stdout to simplify multiple prints --- eris/__main__.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/eris/__main__.py b/eris/__main__.py index 033d777..b7ac7db 100755 --- a/eris/__main__.py +++ b/eris/__main__.py @@ -1122,18 +1122,18 @@ def print_tool_info(): output_file = pager_process.stdin else: output_file = sys.stdout - for tool in sorted(tools.tools_all(), key=lambda t: t.__name__): - 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)" - , file=output_file) - if hasattr(tool, "command"): - print(f"command: {tool.command} foo.{extensions[0]}", file=output_file) - else: - print("function:", "eris.tools." + tool.__name__, file=output_file) - print("url:", tool.url, file=output_file) - extensions = list(extensions_for_tool.get(tool, {"*"})) - print("extensions:", ", ".join(extensions), file=output_file) - print("", file=output_file) + with contextlib.redirect_stdout(output_file): + for tool in sorted(tools.tools_all(), key=lambda t: t.__name__): + 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: + print("function:", "eris.tools." + tool.__name__) + print("url:", tool.url) + extensions = list(extensions_for_tool.get(tool, {"*"})) + print("extensions:", ", ".join(extensions)) + print("") if pager_process is not None: output_file.close() pager_process.wait()