Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color control to goose CLI #1092

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions crates/goose-cli/src/commands/configure.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ use serde_json::{json, Value};
use std::collections::HashMap;
use std::error::Error;

pub async fn handle_configure() -> Result<(), Box<dyn Error>> {
pub async fn handle_configure(color_mode: &str) -> Result<(), Box<dyn Error>> {
let config = Config::global();

if !config.exists() {
@@ -25,7 +25,7 @@ pub async fn handle_configure() -> Result<(), Box<dyn Error>> {
);
println!();
cliclack::intro(style(" goose-configure ").on_cyan().black())?;
match configure_provider_dialog().await {
match configure_provider_dialog(color_mode).await {
Ok(true) => {
println!(
"\n {}: Run '{}' again to adjust your config or add extensions",
@@ -135,16 +135,16 @@ pub async fn handle_configure() -> Result<(), Box<dyn Error>> {
.interact()?;

match action {
"toggle" => toggle_extensions_dialog(),
"add" => configure_extensions_dialog(),
"providers" => configure_provider_dialog().await.and(Ok(())),
"toggle" => toggle_extensions_dialog(color_mode),
"add" => configure_extensions_dialog(color_mode),
"providers" => configure_provider_dialog(color_mode).await.and(Ok(())),
_ => unreachable!(),
}
}
}

/// Dialog for configuring the AI provider and model
pub async fn configure_provider_dialog() -> Result<bool, Box<dyn Error>> {
pub async fn configure_provider_dialog(color_mode: &str) -> Result<bool, Box<dyn Error>> {
// Get global config instance
let config = Config::global();

@@ -315,7 +315,7 @@ pub async fn configure_provider_dialog() -> Result<bool, Box<dyn Error>> {

/// Configure extensions that can be used with goose
/// Dialog for toggling which extensions are enabled/disabled
pub fn toggle_extensions_dialog() -> Result<(), Box<dyn Error>> {
pub fn toggle_extensions_dialog(color_mode: &str) -> Result<(), Box<dyn Error>> {
let extensions = ExtensionManager::get_all()?;

if extensions.is_empty() {
@@ -361,7 +361,7 @@ pub fn toggle_extensions_dialog() -> Result<(), Box<dyn Error>> {
Ok(())
}

pub fn configure_extensions_dialog() -> Result<(), Box<dyn Error>> {
pub fn configure_extensions_dialog(color_mode: &str) -> Result<(), Box<dyn Error>> {
let extension_type = cliclack::select("What type of extension would you like to add?")
.item(
"built-in",
@@ -452,7 +452,7 @@ pub fn configure_extensions_dialog() -> Result<(), Box<dyn Error>> {
cliclack::confirm("Would you like to add environment variables?").interact()?;

let mut envs = HashMap::new();
if add_env {
if (add_env) {
loop {
let key: String = cliclack::input("Environment variable name:")
.placeholder("API_KEY")
14 changes: 14 additions & 0 deletions crates/goose-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -26,6 +26,9 @@ struct Cli {
#[arg(short = 'v', long = "version")]
version: bool,

#[arg(long, value_name = "WHEN", default_value = "auto", value_parser = ["auto", "always", "never", "base16"], help = "Control color output")]
color: String,

#[command(subcommand)]
command: Option<Command>,
}
@@ -164,6 +167,17 @@ async fn main() -> Result<()> {
return Ok(());
}

match cli.color.as_str() {
"auto" => console::set_colors_enabled(true),
"always" => console::set_colors_enabled(true),
"never" => console::set_colors_enabled(false),
"base16" => {
console::set_colors_enabled(true);
std::env::set_var("CLICLACK_COLOR_MODE", "base16");
}
_ => unreachable!(),
}

match cli.command {
Some(Command::Configure {}) => {
let _ = handle_configure().await;
26 changes: 15 additions & 11 deletions crates/goose-cli/src/prompt/renderer.rs
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ impl ToolRenderer for DefaultRenderer {
default_print_request_header(call);

// Format and print the parameters
print_params(&call.arguments, 0);
print_params(&call.arguments, 0, theme);
print_newline();
}
Err(e) => print_markdown(&e.to_string(), theme),
@@ -184,7 +184,7 @@ impl ToolRenderer for TextEditorRenderer {
other_args.insert(k.clone(), v.clone());
}
}
print_params(&Value::Object(other_args), 0);
print_params(&Value::Object(other_args), 0, theme);
}
print_newline();
}
@@ -214,7 +214,7 @@ impl ToolRenderer for BashDeveloperExtensionRenderer {
Some(Value::String(s)) => {
println!("{}: {}", style("command").dim(), style(s).green());
}
_ => print_params(&call.arguments, 0),
_ => print_params(&call.arguments, 0, theme),
}
print_newline();
}
@@ -326,17 +326,21 @@ pub fn default_print_request_header(call: &ToolCall) {
}

pub fn print_markdown(content: &str, theme: &str) {
bat::PrettyPrinter::new()
let mut printer = bat::PrettyPrinter::new()
.input(bat::Input::from_bytes(content.as_bytes()))
.theme(theme)
.language("Markdown")
.wrapping_mode(WrappingMode::Character)
.print()
.unwrap();
.wrapping_mode(WrappingMode::Character);

if std::env::var("CLICLACK_COLOR_MODE").unwrap_or_default() == "base16" {
printer = printer.color_mode(bat::ColorMode::Ansi);
}

printer.print().unwrap();
}

/// Format and print parameters recursively with proper indentation and colors
pub fn print_params(value: &Value, depth: usize) {
pub fn print_params(value: &Value, depth: usize, theme: &str) {
let indent = INDENT.repeat(depth);

match value {
@@ -345,13 +349,13 @@ pub fn print_params(value: &Value, depth: usize) {
match val {
Value::Object(_) => {
println!("{}{}:", indent, style(key).dim());
print_params(val, depth + 1);
print_params(val, depth + 1, theme);
}
Value::Array(arr) => {
println!("{}{}:", indent, style(key).dim());
for item in arr.iter() {
println!("{}{}- ", indent, INDENT);
print_params(item, depth + 2);
print_params(item, depth + 2, theme);
}
}
Value::String(s) => {
@@ -376,7 +380,7 @@ pub fn print_params(value: &Value, depth: usize) {
Value::Array(arr) => {
for (i, item) in arr.iter().enumerate() {
println!("{}{}.", indent, i + 1);
print_params(item, depth + 1);
print_params(item, depth + 1, theme);
}
}
Value::String(s) => {
4 changes: 3 additions & 1 deletion crates/goose-cli/src/prompt/rustyline.rs
Original file line number Diff line number Diff line change
@@ -21,10 +21,11 @@ pub struct RustylinePrompt {
theme: Theme,
renderers: HashMap<String, Box<dyn ToolRenderer>>,
editor: DefaultEditor,
color_mode: String,
}

impl RustylinePrompt {
pub fn new() -> Self {
pub fn new(color_mode: &str) -> Self {
let mut renderers: HashMap<String, Box<dyn ToolRenderer>> = HashMap::new();
let default_renderer = DefaultRenderer;
renderers.insert(default_renderer.tool_name(), Box::new(default_renderer));
@@ -61,6 +62,7 @@ impl RustylinePrompt {
.unwrap_or(Theme::Dark),
renderers,
editor,
color_mode: color_mode.to_string(),
}
}
}
15 changes: 11 additions & 4 deletions documentation/docs/guides/goose-cli-commands.md
Original file line number Diff line number Diff line change
@@ -80,6 +80,14 @@ Starts the session with the specified [built-in extension](/docs/getting-started
goose session --with-builtin <name>
```

- **`--color <WHEN>`**

Control color output. Options: `auto` (default), `always`, `never`, and `base16`.

```bash
goose session --color <when>
```

### run [options]

Execute commands from an instruction file or stdin
@@ -88,6 +96,7 @@ Execute commands from an instruction file or stdin
- **`-t, --text <TEXT>`**: Input text to provide to Goose directly
- **`-n, --name <NAME>`**: Name for this run session (e.g., 'daily-tasks')
- **`-r, --resume`**: Resume from a previous run
- **`--color <WHEN>`**: Control color output. Options: `auto` (default), `always`, `never`, and `base16`.

**Usage:**
```bash
@@ -98,9 +107,7 @@ goose run --instructions plan.md

Configure Goose settings - providers, extensions, etc.



**Usage:**
```bash
goose configure'
```
goose configure
```
Loading