Skip to content

Commit

Permalink
Putting command palette theme auto preview behind a config option
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Jul 24, 2024
1 parent a431aa1 commit 5e63ee2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" }
Expand Down
12 changes: 12 additions & 0 deletions src/posting/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,13 +683,23 @@ 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

@on(CommandPalette.OptionHighlighted)
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.
Expand All @@ -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

Expand Down
12 changes: 12 additions & 0 deletions src/posting/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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."""

Expand Down

0 comments on commit 5e63ee2

Please sign in to comment.