From 9d67e456d70d30d07828e537015777bf4c427723 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sat, 22 Jun 2024 18:20:16 +0100 Subject: [PATCH] command palette tweaks --- src/textual/app.py | 4 ++-- src/textual/command.py | 25 ++++++++++++++----------- src/textual/screen.py | 2 +- src/textual/widgets/_option_list.py | 5 ++++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/textual/app.py b/src/textual/app.py index f34ca20370..7b47639b82 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -109,7 +109,7 @@ Screen, ScreenResultCallbackType, ScreenResultType, - _SystemModalScreen, + SystemModalScreen, ) from .signal import Signal from .timer import Timer @@ -696,7 +696,7 @@ def children(self) -> Sequence["Widget"]: next( screen for screen in reversed(self._screen_stack) - if not isinstance(screen, _SystemModalScreen) + if not isinstance(screen, SystemModalScreen) ), ) except StopIteration: diff --git a/src/textual/command.py b/src/textual/command.py index 2c1b7bc25a..80a8a519cf 100644 --- a/src/textual/command.py +++ b/src/textual/command.py @@ -36,7 +36,7 @@ from .fuzzy import Matcher from .message import Message from .reactive import var -from .screen import Screen, _SystemModalScreen +from .screen import Screen, SystemModalScreen from .timer import Timer from .types import CallbackType, IgnoreReturnCallbackType from .widget import Widget @@ -349,12 +349,13 @@ class CommandList(OptionList, can_focus=False): CommandList { visibility: hidden; border-top: blank; - border-bottom: hkey $primary; + border-bottom: hkey $background; border-left: none; border-right: none; height: auto; max-height: 70vh; background: $panel; + padding: 0; } CommandList:focus { @@ -374,7 +375,7 @@ class CommandList(OptionList, can_focus=False): } CommandList > .option-list--option { - padding-left: 1; + padding-left: 2; } """ @@ -416,7 +417,7 @@ class CommandInput(Input): """ -class CommandPalette(_SystemModalScreen[CallbackType]): +class CommandPalette(SystemModalScreen[CallbackType]): """The Textual command palette.""" COMPONENT_CLASSES: ClassVar[set[str]] = { @@ -431,17 +432,19 @@ class CommandPalette(_SystemModalScreen[CallbackType]): """ DEFAULT_CSS = """ + + CommandPalette:inline { /* If the command palette is invoked in inline mode, we may need additional lines. */ min-height: 20; } CommandPalette { - background: $background 30%; - align-horizontal: center; + background: $background 50%; + align-horizontal: center; } CommandPalette > .command-palette--help-text { - text-style: dim; + text-style: dim not bold; } CommandPalette:dark > .command-palette--highlight { @@ -455,15 +458,15 @@ class CommandPalette(_SystemModalScreen[CallbackType]): CommandPalette > Vertical { margin-top: 3; - width: 90%; + # width: 90%; height: 100%; - visibility: hidden; + visibility: hidden; } CommandPalette #--input { height: auto; visibility: visible; - border: hkey $primary; + border: hkey $background; background: $panel; } @@ -623,7 +626,7 @@ def compose(self) -> ComposeResult: with Vertical(): with Horizontal(id="--input"): yield SearchIcon() - yield CommandInput(placeholder="Command Palette Search...") + yield CommandInput(placeholder="Search for commands…") if not self.run_on_select: yield Button("\u25b6") with Vertical(id="--results"): diff --git a/src/textual/screen.py b/src/textual/screen.py index b7c6b9123e..f3e7f3e3b5 100644 --- a/src/textual/screen.py +++ b/src/textual/screen.py @@ -1318,7 +1318,7 @@ def __init__( self._modal = True -class _SystemModalScreen(ModalScreen[ScreenResultType], inherit_css=False): +class SystemModalScreen(ModalScreen[ScreenResultType], inherit_css=False): """A variant of `ModalScreen` for internal use. This version of `ModalScreen` allows us to build system-level screens; diff --git a/src/textual/widgets/_option_list.py b/src/textual/widgets/_option_list.py index b624a8f358..0b4e775e11 100644 --- a/src/textual/widgets/_option_list.py +++ b/src/textual/widgets/_option_list.py @@ -848,7 +848,10 @@ def render_line(self, y: int) -> Strip: style, self.scrollable_content_region.width - self._left_gutter_width(), ) - strip = strips[y_offset] + try: + strip = strips[y_offset] + except IndexError: + return Strip([]) return strip def scroll_to_highlight(self, top: bool = False) -> None: