Respect the terminal emulator's base colors (#1098)

This commit is contained in:
Nick Johnson
2025-02-05 15:01:13 -08:00
committed by GitHub
parent 745b671950
commit 691a065a26
3 changed files with 14 additions and 3 deletions

View File

@@ -35,4 +35,5 @@ pub enum InputType {
pub enum Theme { pub enum Theme {
Light, Light,
Dark, Dark,
Ansi, // Use terminal's ANSI/base16 colors directly.
} }

View File

@@ -231,6 +231,7 @@ pub fn render(message: &Message, theme: &Theme, renderers: HashMap<String, Box<d
let theme = match theme { let theme = match theme {
Theme::Light => "GitHub", Theme::Light => "GitHub",
Theme::Dark => "zenburn", Theme::Dark => "zenburn",
Theme::Ansi => "base16",
}; };
let mut last_tool_name: &str = "default"; let mut last_tool_name: &str = "default";

View File

@@ -10,11 +10,14 @@ use super::{
use anyhow::Result; use anyhow::Result;
use cliclack::spinner; use cliclack::spinner;
use console::style;
use goose::message::Message; use goose::message::Message;
use mcp_core::Role; use mcp_core::Role;
use rustyline::{DefaultEditor, EventHandler, KeyCode, KeyEvent, Modifiers}; 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 { pub struct RustylinePrompt {
spinner: cliclack::ProgressBar, spinner: cliclack::ProgressBar,
@@ -54,6 +57,8 @@ impl RustylinePrompt {
.map(|val| { .map(|val| {
if val.eq_ignore_ascii_case("light") { if val.eq_ignore_ascii_case("light") {
Theme::Light Theme::Light
} else if val.eq_ignore_ascii_case("ansi") {
Theme::Ansi
} else { } else {
Theme::Dark Theme::Dark
} }
@@ -81,7 +86,7 @@ impl Prompt for RustylinePrompt {
} }
fn get_input(&mut self) -> Result<Input> { 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 { let mut message_text = match input {
Ok(text) => { Ok(text) => {
// Add valid input to history // Add valid input to history
@@ -119,6 +124,10 @@ impl Prompt for RustylinePrompt {
Theme::Dark Theme::Dark
} }
Theme::Dark => { Theme::Dark => {
println!("Switching to Ansi theme");
Theme::Ansi
}
Theme::Ansi => {
println!("Switching to Light theme"); println!("Switching to Light theme");
Theme::Light Theme::Light
} }
@@ -132,7 +141,7 @@ impl Prompt for RustylinePrompt {
{ {
println!("Commands:"); println!("Commands:");
println!("/exit - Exit the session"); 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!("/? | /help - Display this help message");
println!("Ctrl+C - Interrupt goose (resets the interaction to before the interrupted user request)"); println!("Ctrl+C - Interrupt goose (resets the interaction to before the interrupted user request)");
println!("Ctrl+j - Adds a newline"); println!("Ctrl+j - Adds a newline");