From d1716234cc858edacc5cebbb12b87cda76d2baa8 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 17 Sep 2024 15:59:50 +0100 Subject: [PATCH] snapshot test --- src/textual/color.py | 2 +- src/textual/command.py | 4 + src/textual/renderables/background_screen.py | 14 ++ src/textual/screen.py | 3 + src/textual/widget.py | 1 + .../test_ansi_command_palette.svg | 159 ++++++++++++++++++ tests/snapshot_tests/test_snapshots.py | 20 +++ 7 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 tests/snapshot_tests/__snapshots__/test_snapshots/test_ansi_command_palette.svg diff --git a/src/textual/color.py b/src/textual/color.py index ae30f996cf..0b90825539 100644 --- a/src/textual/color.py +++ b/src/textual/color.py @@ -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 diff --git a/src/textual/command.py b/src/textual/command.py index d6e314dc11..b3deebb9c4 100644 --- a/src/textual/command.py +++ b/src/textual/command.py @@ -459,6 +459,10 @@ class CommandPalette(SystemModalScreen): #--container { display: none; } + + &:ansi { + background: transparent; + } } CommandPalette.-ready { diff --git a/src/textual/renderables/background_screen.py b/src/textual/renderables/background_screen.py index 1d901c29b0..628cadce66 100644 --- a/src/textual/renderables/background_screen.py +++ b/src/textual/renderables/background_screen.py @@ -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: diff --git a/src/textual/screen.py b/src/textual/screen.py index b0081a9347..8b38ebfede 100644 --- a/src/textual/screen.py +++ b/src/textual/screen.py @@ -1449,6 +1449,9 @@ class ModalScreen(Screen[ScreenResultType]): layout: vertical; overflow-y: auto; background: $background 60%; + &:ansi { + background: transparent; + } } """ diff --git a/src/textual/widget.py b/src/textual/widget.py index 2e996fb206..7193ecec25 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -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() diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_ansi_command_palette.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_ansi_command_palette.svg new file mode 100644 index 0000000000..1f114ad304 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_ansi_command_palette.svg @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CommandPaletteApp + + + + + + + + + + RedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + +🔎Search for commands… + + +  Quit the application                                                           +Quit the application as soon as possible +  Save screenshot                                                                +Save an SVG 'screenshot' of the current screen +  Show keys and help panel                                                       +Show help for the focused widget and a summary of available keys +▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed +MagentaRedMagentaRedMagentaRedMagentaRedMagentaRedMagentaRed + + + diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index b0b675adc9..687d4da40f 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -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)