Skip to content

Commit

Permalink
Implement color config
Browse files Browse the repository at this point in the history
  • Loading branch information
lusingander committed Feb 22, 2025
1 parent 7b2633c commit 8ac64cd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ clap = { version = "4.5.30", features = ["derive"] }
console = "0.15.10"
fuzzy-matcher = "0.3.7"
laurier = "0.1.0"
ratatui = "0.29.0"
ratatui = { version = "0.29.0", features = ["serde"] }
serde = { version = "1.0.218", features = ["derive"] }
toml = "0.8.20"
tui-input = "0.11.1"
umbra = "0.3.0"
11 changes: 9 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ use std::{env, path::PathBuf};

use ratatui::style::Color;
use serde::Deserialize;
use umbra::optional;

use crate::MatchType;

const CONFIG_PATH_ENV_VAR: &str = "CARGO_SELECTOR_CONFIG";

#[derive(Debug, Default, PartialEq, Eq, Deserialize)]
#[optional(derives = [Deserialize])]
#[derive(Debug, Default, PartialEq, Eq)]
pub struct Config {
pub match_type: Option<MatchType>,
#[nested]
pub color: ColorTheme,
}

impl Config {
pub fn load() -> Config {
if let Some(path) = config_file_path() {
let content = std::fs::read_to_string(path).unwrap();
toml::from_str(&content).unwrap()
let config: OptionalConfig = toml::from_str(&content).unwrap();
config.into()
} else {
Config::default()
}
Expand All @@ -27,6 +32,8 @@ fn config_file_path() -> Option<PathBuf> {
env::var(CONFIG_PATH_ENV_VAR).map(PathBuf::from).ok()
}

#[optional(derives = [Deserialize])]
#[derive(Debug, PartialEq, Eq)]
pub struct ColorTheme {
pub bg: Color,

Expand Down
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use ratatui::{
use serde::Deserialize;

use crate::{
config::{ColorTheme, Config},
config::Config,
matcher::Matcher,
tui::{Ret, Tui},
};
Expand Down Expand Up @@ -159,8 +159,7 @@ fn main() -> std::io::Result<ExitCode> {

let config = Config::load();
let match_type = match_type.or(config.match_type).unwrap_or_default();

let theme = ColorTheme::default();
let theme = config.color;

let mut targets = cargo::get_all_targets();
if let Some(kind) = kind {
Expand Down

0 comments on commit 8ac64cd

Please sign in to comment.