feat(goose-cli): theme persistence & selection (#1693)
Co-authored-by: Bradley Axen <baxen@squareup.com>
This commit is contained in:
@@ -11,6 +11,7 @@ pub enum InputResult {
|
||||
AddExtension(String),
|
||||
AddBuiltin(String),
|
||||
ToggleTheme,
|
||||
SelectTheme(String),
|
||||
Retry,
|
||||
ListPrompts(Option<String>),
|
||||
PromptCommand(PromptCommandOptions),
|
||||
@@ -103,6 +104,22 @@ fn handle_slash_command(input: &str) -> Option<InputResult> {
|
||||
Some(InputResult::Retry)
|
||||
}
|
||||
"/t" => Some(InputResult::ToggleTheme),
|
||||
s if s.starts_with("/t ") => {
|
||||
let t = s
|
||||
.strip_prefix("/t ")
|
||||
.unwrap_or_default()
|
||||
.trim()
|
||||
.to_lowercase();
|
||||
if ["light", "dark", "ansi"].contains(&t.as_str()) {
|
||||
Some(InputResult::SelectTheme(t))
|
||||
} else {
|
||||
println!(
|
||||
"Theme Unavailable: {} Available themes are: light, dark, ansi",
|
||||
t
|
||||
);
|
||||
Some(InputResult::Retry)
|
||||
}
|
||||
}
|
||||
"/prompts" => Some(InputResult::ListPrompts(None)),
|
||||
s if s.starts_with(CMD_PROMPTS) => {
|
||||
// Parse arguments for /prompts command
|
||||
@@ -234,6 +251,7 @@ fn print_help() {
|
||||
"Available commands:
|
||||
/exit or /quit - Exit the session
|
||||
/t - Toggle Light/Dark/Ansi theme
|
||||
/t <name> - Set theme directly (light, dark, ansi)
|
||||
/extension <command> - Add a stdio extension (format: ENV1=val1 command args...)
|
||||
/builtin <names> - Add builtin extensions by name (comma-separated)
|
||||
/prompts [--extension <name>] - List all available prompts, optionally filtered by extension
|
||||
|
||||
@@ -499,6 +499,28 @@ impl Session {
|
||||
output::set_theme(new_theme);
|
||||
continue;
|
||||
}
|
||||
|
||||
input::InputResult::SelectTheme(theme_name) => {
|
||||
save_history(&mut editor);
|
||||
|
||||
let new_theme = match theme_name.as_str() {
|
||||
"light" => {
|
||||
println!("Switching to Light theme");
|
||||
output::Theme::Light
|
||||
}
|
||||
"dark" => {
|
||||
println!("Switching to Dark theme");
|
||||
output::Theme::Dark
|
||||
}
|
||||
"ansi" => {
|
||||
println!("Switching to Ansi theme");
|
||||
output::Theme::Ansi
|
||||
}
|
||||
_ => output::Theme::Dark,
|
||||
};
|
||||
output::set_theme(new_theme);
|
||||
continue;
|
||||
}
|
||||
input::InputResult::Retry => continue,
|
||||
input::InputResult::ListPrompts(extension) => {
|
||||
save_history(&mut editor);
|
||||
|
||||
@@ -67,6 +67,17 @@ pub fn set_theme(theme: Theme) {
|
||||
.set_param("GOOSE_CLI_THEME", Value::String(theme.as_config_string()))
|
||||
.expect("Failed to set theme");
|
||||
CURRENT_THEME.with(|t| *t.borrow_mut() = theme);
|
||||
|
||||
let config = Config::global();
|
||||
let theme_str = match theme {
|
||||
Theme::Light => "light",
|
||||
Theme::Dark => "dark",
|
||||
Theme::Ansi => "ansi",
|
||||
};
|
||||
|
||||
if let Err(e) = config.set_param("GOOSE_CLI_THEME", Value::String(theme_str.to_string())) {
|
||||
eprintln!("Failed to save theme setting to config: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_theme() -> Theme {
|
||||
|
||||
Reference in New Issue
Block a user