Skip to content

Commit

Permalink
Config for toggling loading builtin themes
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Jul 24, 2024
1 parent cd30aee commit 88eb5d3
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 113 deletions.
Binary file modified .coverage
Binary file not shown.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ Dotenv files are separate from collections, although you may wish to include the
| Config Key (Env Var) | Values (Default) | Description |
|----------------------|------------------|-------------|
| `theme` (`POSTING_THEME`) | `"posting"`, `"galaxy"`, `"monokai"`, `"solarized-light"`, `"nautilus"`, `"nebula"`, `"alpine"`, `"cobalt"`, `"twilight"`, `"hacker"` (Default: `"posting"`) | Sets the theme of the application. |
| `load_user_themes` (`POSTING_LOAD_USER_THEMES`) | `true`, `false` (Default: `true`) | If enabled, load user themes from the theme directory, allowing them to be specified in config and selected via the command palette. |
| `load_builtin_themes` (`POSTING_LOAD_BUILTIN_THEMES`) | `true`, `false` (Default: `true`) | If enabled, load builtin themes, allowing them to be specified in config and selected via the command palette. |
| `theme_directory` (`POSTING_THEME_DIRECTORY`) | (Default: `${XDG_DATA_HOME}/posting/themes`) | The directory containing user themes. |
| `layout` (`POSTING_LAYOUT`) | `"vertical"`, `"horizontal"` (Default: `"horizontal"`) | Sets the layout of the application. |
| `use_host_environment` (`POSTING_USE_HOST_ENVIRONMENT`) | `true`, `false` (Default: `false`) | Allow/deny using environment variables from the host machine in requests via `$env:` syntax. When disabled, only variables defined explicitly in `.env` files will be available for use. |
| `animation` (`POSTING_ANIMATION`) | `"none"`, `"basic"`, `"full"` (Default: `"none"`) | Controls the animation level. |
Expand All @@ -240,7 +243,6 @@ 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. |
| `theme_directory` (`POSTING_THEME_DIRECTORY`) | (Default: `${XDG_DATA_HOME}/posting/themes`) | The directory containing user themes. |
<!-- | `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
9 changes: 7 additions & 2 deletions src/posting/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,16 @@ def __init__(
) -> None:
SETTINGS.set(settings)

available_themes: dict[str, Theme] = {**BUILTIN_THEMES}
available_themes: dict[str, Theme] = {"posting": BUILTIN_THEMES["posting"]}

if settings.load_builtin_themes:
available_themes |= BUILTIN_THEMES

if settings.use_xresources:
available_themes |= load_xresources_themes()

available_themes |= load_user_themes()
if settings.load_user_themes:
available_themes |= load_user_themes()

self.themes = available_themes

Expand Down
8 changes: 8 additions & 0 deletions src/posting/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ class Settings(BaseSettings):
theme_directory: Path = Field(default=theme_directory())
"""The directory containing user themes."""

load_user_themes: bool = Field(default=True)
"""If enabled, load user themes from the theme directory, allowing them
to be specified in config and selected via the command palette."""

load_builtin_themes: bool = Field(default=True)
"""If enabled, load builtin themes, allowing them to be specified
in config and selected via the command palette."""

layout: PostingLayout = Field(default="vertical")
"""Layout for the app."""

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/sample-configs/general.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use_host_environment: false
load_user_themes: false
response:
show_size_and_time: false
heading:
Expand Down
1 change: 1 addition & 0 deletions tests/sample-configs/modified_config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
theme: galaxy
layout: horizontal
use_host_environment: false
load_user_themes: false
response:
show_size_and_time: false
focus:
Expand Down

0 comments on commit 88eb5d3

Please sign in to comment.