diff --git a/README.md b/README.md index b8ade2f0..e8904df7 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,7 @@ Dotenv files are separate from collections, although you may wish to include the | `focus.on_startup` (`POSTING_FOCUS__ON_STARTUP`) | `"url"`, `"method", "collection"` (Default: `"url"`) | Automatically focus the URL bar, method, or collection browser when the app starts. | | `focus.on_response` (`POSTING_FOCUS__ON_RESPONSE`) | `"body"`, `"tabs"` (Default: `unset`)| Automatically focus the response tabs or response body text area when a response is received. | | `text_input.blinking_cursor` (`POSTING_TEXT_INPUT__BLINKING_CURSOR`) | `true`, `false` (Default: `true`) | If enabled, the cursor will blink in input widgets and text area widgets. | +| `command_palette.theme_preview` (`POSTING_COMMAND_PALETTE__THEME_PREVIEW`) | `true`, `false` (Default: `false`) | If enabled, the command palette will display a preview of the selected theme when the cursor is over it. This will slow down cursor movement and so is disabled by default. | | `use_xresources` (`POSTING_USE_XRESOURCES`) | `true`, `false` (Default: `false`) | Try to create themes called `xresources-dark` and `xresources-light` (see the section below) | ## SSL certificate configuration diff --git a/pyproject.toml b/pyproject.toml index 5749fe73..621bc132 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "posting" -version = "1.8.0" +version = "1.9.0" description = "The modern API client that lives in your terminal." authors = [ { name = "Darren Burns", email = "darrenb900@gmail.com" } diff --git a/src/posting/app.py b/src/posting/app.py index 9edce7f2..4d546a42 100644 --- a/src/posting/app.py +++ b/src/posting/app.py @@ -683,6 +683,11 @@ def command_theme(self, theme: str) -> None: @on(CommandPalette.Opened) def palette_opened(self) -> None: + # If the theme preview is disabled, don't record the theme being used + # before the palette is opened. + if not self.settings.command_palette.theme_preview: + return + # Record the theme being used before the palette is opened. self._original_theme = self.theme @@ -690,6 +695,11 @@ def palette_opened(self) -> None: def palette_option_highlighted( self, event: CommandPalette.OptionHighlighted ) -> None: + # If the theme preview is disabled, don't update the theme when an option + # is highlighted. + if not self.settings.command_palette.theme_preview: + return + prompt: Group = event.highlighted_event.option.prompt # TODO: This is making quite a lot of assumptions. Fragile, but the only # way I can think of doing it given the current Textual APIs. @@ -712,6 +722,8 @@ def palette_closed(self, event: CommandPalette.Closed) -> None: # If we closed with a result, that will be handled by the command # being triggered. However, if we closed the palette with no result # then make sure we revert the theme back. + if not self.settings.command_palette.theme_preview: + return if not event.option_selected: self.theme = self._original_theme diff --git a/src/posting/config.py b/src/posting/config.py index c98a4abb..cf5720df 100644 --- a/src/posting/config.py +++ b/src/posting/config.py @@ -76,6 +76,13 @@ class TextInputSettings(BaseModel): """If enabled, the cursor will blink in input widgets and text areas.""" +class CommandPaletteSettings(BaseModel): + """Configuration for the command palette.""" + + theme_preview: bool = Field(default=False) + """If enabled, the command palette will display a preview of the selected theme when the cursor is over it.""" + + class Settings(BaseSettings): model_config = SettingsConfigDict( env_file=".env", @@ -123,6 +130,11 @@ class Settings(BaseSettings): url_bar: UrlBarSettings = Field(default_factory=UrlBarSettings) """Configuration for the URL bar.""" + command_palette: CommandPaletteSettings = Field( + default_factory=CommandPaletteSettings + ) + """Configuration for the command palette.""" + pager: str | None = Field(default=os.getenv("PAGER")) """The command to use for paging."""