-
Notifications
You must be signed in to change notification settings - Fork 163
feat(BA-3803): add stdout logging for --headless mode #7885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f69ce75
2585038
fca99af
faa3d59
63f2e81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,9 @@ | |
| import asyncio | ||
| from pathlib import Path | ||
|
|
||
| from rich.console import ConsoleRenderable | ||
| from rich.console import Console, ConsoleRenderable | ||
| from rich.text import Text | ||
| from rich.traceback import Traceback | ||
| from textual import on | ||
| from textual.app import ComposeResult | ||
| from textual.binding import Binding | ||
|
|
@@ -44,9 +45,51 @@ class SetupLog(RichLog): | |
| Binding("enter", "continue", show=False), | ||
| ] | ||
|
|
||
| def __init__(self, *args, **kwargs) -> None: | ||
| def __init__( | ||
| self, | ||
| *args, | ||
| non_interactive: bool = False, | ||
| **kwargs, | ||
| ) -> None: | ||
| super().__init__(*args, **kwargs) | ||
| self._continue = asyncio.Event() | ||
| self._non_interactive = non_interactive | ||
| self._stdout_console: Console | None = None | ||
| if self._non_interactive: | ||
| self._stdout_console = Console(force_terminal=True) | ||
|
|
||
| def _write_to_stdout(self, content: object) -> None: | ||
| """Write content to stdout via Rich Console.""" | ||
| if self._stdout_console is None: | ||
| return | ||
| try: | ||
| if isinstance(content, (str, Text, Traceback)): | ||
| self._stdout_console.print(content) | ||
| elif isinstance(content, Exception): | ||
| self._stdout_console.print(f"[red]Error: {content}[/red]") | ||
| self._stdout_console.print_exception() | ||
| else: | ||
| self._stdout_console.print(content) | ||
| except Exception: | ||
| pass | ||
|
Comment on lines
+73
to
+74
|
||
|
|
||
| def write( | ||
| self, | ||
| content: object, | ||
| width: int | None = None, | ||
| expand: bool = False, | ||
| shrink: bool = True, | ||
| scroll_end: bool | None = None, | ||
| ) -> SetupLog: | ||
| """Write content to the log and optionally to stdout.""" | ||
| # Always write to the RichLog widget | ||
| super().write(content, width=width, expand=expand, shrink=shrink, scroll_end=scroll_end) | ||
|
|
||
| # Write to stdout if non-interactive mode | ||
| if self._non_interactive: | ||
| self._write_to_stdout(content) | ||
|
|
||
| return self | ||
|
|
||
| async def wait_continue(self) -> None: | ||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When handling Exception objects, print_exception() is called without arguments, which prints the currently active exception from sys.exc_info(). However, the Exception object passed to this method may not be the currently active exception. Consider passing the exception object explicitly to print_exception() or using print() with the exception object directly, which would be more consistent with the error message on line 69.