Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd2/rich_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ def __init__(
force_terminal: bool | None = None
force_interactive: bool | None = None

color_system: str | None = "auto"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type hint for color_system should be Literal['auto', 'standard', '256', 'truecolor', 'windows']

Will need to add Literal to imports from `typing.


if ALLOW_STYLE == AllowStyle.ALWAYS:
force_terminal = True
color_system = "truecolor"

# Turn off interactive mode if dest is not a terminal which supports it.
tmp_console = Console(file=file)
Expand All @@ -179,6 +182,7 @@ def __init__(
file=file,
force_terminal=force_terminal,
force_interactive=force_interactive,
color_system=color_system,
theme=APP_THEME,
**kwargs,
)
Expand Down Expand Up @@ -414,6 +418,7 @@ def rich_text_to_string(text: Text) -> str:

console = Console(
force_terminal=True,
color_system="truecolor",
soft_wrap=True,
no_color=False,
theme=APP_THEME,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3756,6 +3756,9 @@ def test_ansi_terminal_tty(mocker, capsys) -> None:
app = AnsiApp()
mocker.patch.object(app.stdout, 'isatty', return_value=True)
mocker.patch.object(sys.stderr, 'isatty', return_value=True)
# Simulate a color-capable terminal: TERMINAL mode respects the TERM env var,
# so TERM=dumb would suppress colors even with isatty=True.
mocker.patch.dict('os.environ', {'TERM': 'xterm-256color'})

app.onecmd_plus_hooks('echo_error oopsie')
# if colors are on, the output should have some ANSI style sequences in it
Expand Down
Loading