Skip to content

Commit

Permalink
Consolidated use of rich console
Browse files Browse the repository at this point in the history
Includes:
- use enrich Console for both console and logger
- use the same theme for both
- respect coloring enablement for logger
  • Loading branch information
ssbarnea committed Nov 18, 2020
1 parent 9164ddf commit fd63c7f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ install_requires =
click-completion >= 0.5.1
click-help-colors >= 0.6
cookiecutter >= 1.6.0, != 1.7.1
enrich >= 1.2
enrich >= 1.2.1
Jinja2 >= 2.10.1
packaging
paramiko >= 2.5.0, < 3
Expand Down
4 changes: 2 additions & 2 deletions src/molecule/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import sys
from typing import Any

from enrich.console import Console
from rich.style import Style
from rich.theme import Theme
from subprocess_tee.rich import ConsoleEx

theme = Theme(
{
Expand Down Expand Up @@ -60,6 +60,6 @@ def should_do_markup() -> bool:
return sys.stdout.isatty() and os.environ.get("TERM") != "dumb"


console = ConsoleEx(
console = Console(
force_terminal=should_do_markup(), theme=theme, record=True, redirect=True
)
6 changes: 4 additions & 2 deletions src/molecule/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from enrich.console import Console
from enrich.logging import RichHandler

from molecule.console import console
from molecule.console import console, should_do_markup, theme
from molecule.text import chomp

SUCCESS = 100
Expand Down Expand Up @@ -100,4 +100,6 @@ def get_logger(name=None) -> logging.Logger:
return logger


LOGGING_CONSOLE = Console(file=sys.stderr, force_terminal=True)
LOGGING_CONSOLE = Console(
file=sys.stderr, force_terminal=should_do_markup(), theme=theme
)

0 comments on commit fd63c7f

Please sign in to comment.