diff --git a/src/molecule/console.py b/src/molecule/console.py index fe02478fe8..d9b25d6d13 100644 --- a/src/molecule/console.py +++ b/src/molecule/console.py @@ -1,7 +1,7 @@ """Console and terminal utilities.""" import os import sys -from typing import Any +from typing import Any, Dict from enrich.console import Console from rich.style import Style @@ -71,9 +71,15 @@ def should_do_markup() -> bool: return sys.stdout.isatty() +console_options: Dict[str, Any] = {"emoji": False, "theme": theme, "soft_wrap": True} + console = Console( force_terminal=should_do_markup(), theme=theme, record=True, redirect=True ) +console_options_stderr = console_options.copy() +console_options_stderr["stderr"] = True +console_stderr: Console = Console(**console_options_stderr) + # Define ANSIBLE_FORCE_COLOR if markup is enabled and another value is not # already given. This assures that Ansible subprocesses are still colored, # even if they do not run with a real TTY. diff --git a/src/molecule/logger.py b/src/molecule/logger.py index 460e110d27..d98753b5f5 100644 --- a/src/molecule/logger.py +++ b/src/molecule/logger.py @@ -27,7 +27,7 @@ from enrich.logging import RichHandler -from molecule.console import console +from molecule.console import console, console_stderr from molecule.text import underscore LOG = logging.getLogger(__name__) @@ -48,7 +48,7 @@ def configure() -> None: # libraries. logger = logging.getLogger() handler = RichHandler( - console=console, show_time=False, show_path=False, markup=True + console=console_stderr, show_time=False, show_path=False, markup=True ) # type: ignore logger.addHandler(handler) logger.propagate = False