-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pydantic, add theme reactive to app
- Loading branch information
1 parent
35d9068
commit f1cabd4
Showing
6 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from pydantic import BaseModel, Field | ||
import yaml | ||
|
||
from elia_chat.locations import theme_directory | ||
|
||
|
||
class Theme(BaseModel): | ||
name: str = Field(exclude=True) | ||
primary: str | ||
secondary: str | None = None | ||
background: str | None = None | ||
surface: str | None = None | ||
panel: str | None = None | ||
warning: str | None = None | ||
error: str | None = None | ||
success: str | None = None | ||
accent: str | None = None | ||
dark: bool = True | ||
|
||
|
||
def load_user_themes() -> dict[str, Theme]: | ||
"""Load user themes from "~/.config/elia/themes". | ||
Returns: | ||
A dictionary mapping theme names to theme objects. | ||
""" | ||
themes: dict[str, Theme] = {} | ||
for path in theme_directory().iterdir(): | ||
path_suffix = path.suffix | ||
if path_suffix == ".yaml" or path_suffix == ".yml": | ||
with path.open() as theme_file: | ||
theme_content = yaml.load(theme_file, Loader=yaml.FullLoader) or {} | ||
try: | ||
themes[theme_content["name"]] = Theme(**theme_content) | ||
except KeyError: | ||
raise ValueError( | ||
f"Invalid theme file {path}. A `name` is required." | ||
) | ||
return themes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.