theme is now in the config file

This commit is contained in:
filipriec
2025-02-22 19:06:33 +01:00
parent 0c1a1212e3
commit 7acd1707f1
5 changed files with 25 additions and 25 deletions

View File

@@ -1,24 +0,0 @@
.
├── ./colors.rs
└── components1/
├── ./components1/mod.rs
├── ./components1/models.rs
├── ./components1/handlers.rs
└── handlers/
├── ./components1/handlers/command_line.rs
├── ./components1/handlers/form.rs
├── ./components1/handlers/mod.rs
├── ./components1/handlers/preview_card.rs
└── ./components1/handlers/status_line.rs
├── ./config.rs
├── ./mod.rs
├── ./terminal.rs
├── ./ui.rs
└── ./ui
├── ./ui/mod.rs
├── ./ui/models.rs
├── ./ui/handlers.rs
└── handlers/
├── ./ui/handlers/x.rs
├── ./ui/handlers/x2.rs
└── ./ui/handlers/x3.rs

View File

@@ -13,3 +13,7 @@ move_left = ["h"]
move_right = ["l"]
move_up = ["k", "Up"]
move_down = ["j", "Down"]
[colors]
theme = "dark"
# Options: "light", "dark", "high_contrast"

View File

@@ -13,6 +13,14 @@ pub struct Theme {
}
impl Theme {
pub fn from_str(theme_name: &str) -> Self {
match theme_name.to_lowercase().as_str() {
"dark" => Self::dark(),
"high_contrast" => Self::high_contrast(),
_ => Self::light(),
}
}
// Default light theme
pub fn light() -> Self {
Self {

View File

@@ -3,9 +3,21 @@ use serde::Deserialize;
use std::collections::HashMap;
use crossterm::event::{KeyCode, KeyModifiers};
#[derive(Debug, Deserialize, Default)]
pub struct ColorsConfig {
#[serde(default = "default_theme")]
pub theme: String,
}
fn default_theme() -> String {
"light".to_string()
}
#[derive(Debug, Deserialize)]
pub struct Config {
pub keybindings: HashMap<String, Vec<String>>,
#[serde(default)]
pub colors: ColorsConfig,
}
impl Config {

View File

@@ -8,7 +8,7 @@ use crate::client::ui::handlers::{event::EventHandler, form::FormState, state::A
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::load()?;
let mut app_terminal = AppTerminal::new().await?;
let theme = Theme::dark();
let theme = Theme::from_str(&config.colors.theme);
// Fetch table structure at startup (one-time)
// TODO: Later, consider implementing a live update for table structure changes.