Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions cmd2/pt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@

BASE_DELIMITERS = " \t\n" + "".join(constants.QUOTES) + "".join(constants.REDIRECTION_CHARS)

# prompt_toolkit accepts these standard ANSI color names directly
# prompt_toolkit accepts these standard ANSI color names directly. Its names for colors 7 and 15 are
# unusual: normal white (SGR 37) is "ansigray" and bright white (SGR 97) is "ansiwhite". It has no
# "ansibrightwhite", which it rejects as a bad color format.
ANSI_NAMES = (
"ansiblack",
"ansired",
Expand All @@ -61,15 +63,15 @@
"ansiblue",
"ansimagenta",
"ansicyan",
"ansiwhite",
"ansigray",
"ansibrightblack",
"ansibrightred",
"ansibrightgreen",
"ansibrightyellow",
"ansibrightblue",
"ansibrightmagenta",
"ansibrightcyan",
"ansibrightwhite",
"ansiwhite",
)


Expand Down
16 changes: 16 additions & 0 deletions tests/test_pt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,22 @@ def test_rich_to_pt_color_standard(self):
c = Color.from_ansi(2)
assert pt_utils.rich_to_pt_color(c) == "ansigreen"

def test_rich_to_pt_color_white_is_not_bright_white(self):
from rich.color import Color

# Rich's "white" is SGR 37, which prompt_toolkit calls "ansigray". Its "ansiwhite" is SGR 97.
assert pt_utils.rich_to_pt_color(Color.parse("white")) == "ansigray"
assert pt_utils.rich_to_pt_color(Color.parse("bright_white")) == "ansiwhite"

def test_rich_to_pt_color_standard_colors_are_valid(self):
from prompt_toolkit.styles import Style
from rich.color import Color

# prompt_toolkit raises ValueError for a color name it does not know
for number in range(16):
pt_color = pt_utils.rich_to_pt_color(Color.from_ansi(number))
Style([("x", f"fg:{pt_color}")])

def test_rich_to_pt_color_eight_bit(self):
from rich.color import Color

Expand Down
Loading