Skip to content

Commit

Permalink
Merge pull request #5013 from Textualize/more-ansi
Browse files Browse the repository at this point in the history
ANSI background issue
  • Loading branch information
willmcgugan authored Sep 17, 2024
2 parents 6043845 + d171623 commit c054af8
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/textual/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def blend(
Returns:
A new color.
"""
if self.ansi is not None:
if destination.ansi is not None:
return destination
if factor <= 0:
return self
Expand Down
4 changes: 4 additions & 0 deletions src/textual/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ class CommandPalette(SystemModalScreen):
#--container {
display: none;
}
&:ansi {
background: transparent;
}
}
CommandPalette.-ready {
Expand Down
14 changes: 14 additions & 0 deletions src/textual/renderables/background_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ def process_segments(

NULL_STYLE = Style()

if color.a == 0:
# Special case for transparent color
for segment in segments:
text, style, control = segment
if control:
yield segment
else:
yield _Segment(
text,
NULL_STYLE if style is None else style.clear_meta_and_links(),
control,
)
return

for segment in segments:
text, style, control = segment
if control:
Expand Down
3 changes: 3 additions & 0 deletions src/textual/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,9 @@ class ModalScreen(Screen[ScreenResultType]):
layout: vertical;
overflow-y: auto;
background: $background 60%;
&:ansi {
background: transparent;
}
}
"""

Expand Down
1 change: 1 addition & 0 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class Widget(DOMNode):
link-background-hover: $accent;
link-color-hover: $text;
link-style-hover: bold not underline;
background: transparent;
}
"""
COMPONENT_CLASSES: ClassVar[set[str]] = set()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1921,3 +1921,23 @@ def compose(self) -> ComposeResult:

app = ANSIApp(ansi_color=True)
assert snap_compare(app)


def test_ansi_command_palette(snap_compare):
"""Test command palette on top of ANSI colors."""

class CommandPaletteApp(App[None]):
CSS = """
Label {
width: 1fr;
}
"""

def compose(self) -> ComposeResult:
yield Label("[red]Red[/] [magenta]Magenta[/] " * 200)

def on_mount(self) -> None:
self.action_command_palette()

app = CommandPaletteApp(ansi_color=True)
assert snap_compare(app)

0 comments on commit c054af8

Please sign in to comment.