Skip to content

Commit

Permalink
Respect the terminal emulator's base colors (block#1098)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyonson authored Feb 5, 2025
1 parent 745b671 commit 691a065
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/goose-cli/src/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ pub enum InputType {
pub enum Theme {
Light,
Dark,
Ansi, // Use terminal's ANSI/base16 colors directly.
}
1 change: 1 addition & 0 deletions crates/goose-cli/src/prompt/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ pub fn render(message: &Message, theme: &Theme, renderers: HashMap<String, Box<d
let theme = match theme {
Theme::Light => "GitHub",
Theme::Dark => "zenburn",
Theme::Ansi => "base16",
};

let mut last_tool_name: &str = "default";
Expand Down
15 changes: 12 additions & 3 deletions crates/goose-cli/src/prompt/rustyline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ use super::{

use anyhow::Result;
use cliclack::spinner;
use console::style;
use goose::message::Message;
use mcp_core::Role;
use rustyline::{DefaultEditor, EventHandler, KeyCode, KeyEvent, Modifiers};

const PROMPT: &str = "\x1b[1m\x1b[38;5;30m( O)> \x1b[0m";
fn get_prompt() -> String {
format!("{} ", style("( O)>").cyan().bold())
}

pub struct RustylinePrompt {
spinner: cliclack::ProgressBar,
Expand Down Expand Up @@ -54,6 +57,8 @@ impl RustylinePrompt {
.map(|val| {
if val.eq_ignore_ascii_case("light") {
Theme::Light
} else if val.eq_ignore_ascii_case("ansi") {
Theme::Ansi
} else {
Theme::Dark
}
Expand Down Expand Up @@ -81,7 +86,7 @@ impl Prompt for RustylinePrompt {
}

fn get_input(&mut self) -> Result<Input> {
let input = self.editor.readline(PROMPT);
let input = self.editor.readline(&get_prompt());
let mut message_text = match input {
Ok(text) => {
// Add valid input to history
Expand Down Expand Up @@ -119,6 +124,10 @@ impl Prompt for RustylinePrompt {
Theme::Dark
}
Theme::Dark => {
println!("Switching to Ansi theme");
Theme::Ansi
}
Theme::Ansi => {
println!("Switching to Light theme");
Theme::Light
}
Expand All @@ -132,7 +141,7 @@ impl Prompt for RustylinePrompt {
{
println!("Commands:");
println!("/exit - Exit the session");
println!("/t - Toggle Light/Dark theme");
println!("/t - Toggle Light/Dark/Ansi theme");
println!("/? | /help - Display this help message");
println!("Ctrl+C - Interrupt goose (resets the interaction to before the interrupted user request)");
println!("Ctrl+j - Adds a newline");
Expand Down

0 comments on commit 691a065

Please sign in to comment.