Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/prompt_toolkit/styles/style_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def transform_attrs(self, attrs: Attrs) -> Attrs:

# If a foreground color is given without a background color.
no_background = not attrs.bgcolor or attrs.bgcolor == "default"
has_fgcolor = attrs.color and attrs.color != "ansidefault"
has_fgcolor = attrs.color and attrs.color not in ("default", "ansidefault")

if has_fgcolor and no_background:
# Calculate new RGB values.
Expand Down
23 changes: 22 additions & 1 deletion tests/test_style_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from prompt_toolkit.styles import AdjustBrightnessStyleTransformation, Attrs
from prompt_toolkit.styles import AdjustBrightnessStyleTransformation, Attrs, Style


@pytest.fixture
Expand Down Expand Up @@ -50,3 +50,24 @@ def test_adjust_brightness_style_transformation(default_attrs):

attrs = tr2.transform_attrs(default_attrs._replace(color="00ffaa"))
assert attrs.color == "00ffaa"


@pytest.mark.parametrize("color", [None, "", "default", "ansidefault"])
@pytest.mark.parametrize("brightness", [(0.5, 1.0), (0.0, 0.5)])
def test_adjust_brightness_preserves_default_foreground(
default_attrs, color, brightness
):
attrs = default_attrs._replace(color=color, bold=True)
tr = AdjustBrightnessStyleTransformation(*brightness)

assert tr.transform_attrs(attrs) == attrs


@pytest.mark.parametrize("style_string", ["fg:default", "fg:default bg:default"])
def test_adjust_brightness_preserves_explicit_default_style(style_string):
style = Style.from_dict({"text": style_string})
attrs = style.get_attrs_for_style_str("class:text")
tr = AdjustBrightnessStyleTransformation(0.5, 1.0)

assert attrs.color == "default"
assert tr.transform_attrs(attrs) == attrs