mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
Make GOOSE_CLI_THEME persist to config file and stick for future session (#2099)
This commit is contained in:
@@ -25,26 +25,43 @@ impl Theme {
|
||||
Theme::Ansi => "base16",
|
||||
}
|
||||
}
|
||||
|
||||
fn from_config_str(val: &str) -> Self {
|
||||
if val.eq_ignore_ascii_case("light") {
|
||||
Theme::Light
|
||||
} else if val.eq_ignore_ascii_case("ansi") {
|
||||
Theme::Ansi
|
||||
} else {
|
||||
Theme::Dark
|
||||
}
|
||||
}
|
||||
|
||||
fn as_config_string(&self) -> String {
|
||||
match self {
|
||||
Theme::Light => "light".to_string(),
|
||||
Theme::Dark => "dark".to_string(),
|
||||
Theme::Ansi => "ansi".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static CURRENT_THEME: RefCell<Theme> = RefCell::new(
|
||||
std::env::var("GOOSE_CLI_THEME")
|
||||
.ok()
|
||||
.map(|val| {
|
||||
if val.eq_ignore_ascii_case("light") {
|
||||
Theme::Light
|
||||
} else if val.eq_ignore_ascii_case("ansi") {
|
||||
Theme::Ansi
|
||||
} else {
|
||||
Theme::Dark
|
||||
}
|
||||
})
|
||||
.unwrap_or(Theme::Dark)
|
||||
std::env::var("GOOSE_CLI_THEME").ok()
|
||||
.map(|val| Theme::from_config_str(&val))
|
||||
.unwrap_or_else(||
|
||||
Config::global().get_param::<String>("GOOSE_CLI_THEME").ok()
|
||||
.map(|val| Theme::from_config_str(&val))
|
||||
.unwrap_or(Theme::Dark)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
pub fn set_theme(theme: Theme) {
|
||||
let config = Config::global();
|
||||
config
|
||||
.set_param("GOOSE_CLI_THEME", Value::String(theme.as_config_string()))
|
||||
.expect("Failed to set theme");
|
||||
CURRENT_THEME.with(|t| *t.borrow_mut() = theme);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user