Skip to content

Commit c3fb079

Browse files
author
Olivier Mansour
committed
fix: clean up --quiet mode output by suppressing UI elements
- Suppress spinner cleanup operations in quiet mode - Suppress cursor operations and terminal clearing - Suppress notification bells and color resets to stderr - Suppress newlines during tool execution flow - Force disable markdown rendering to eliminate ANSI codes - Maintain complete response output and proper termination Result: Clean, minimal output perfect for scripting and automation
1 parent 17b0b27 commit c3fb079

File tree

1 file changed

+56
-32
lines changed
  • crates/chat-cli/src/cli/chat

1 file changed

+56
-32
lines changed

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,13 @@ impl ChatSession {
808808

809809
if self.spinner.is_some() {
810810
drop(self.spinner.take());
811-
queue!(
812-
self.stderr,
813-
terminal::Clear(terminal::ClearType::CurrentLine),
814-
cursor::MoveToColumn(0),
815-
)?;
811+
if !self.quiet {
812+
queue!(
813+
self.stderr,
814+
terminal::Clear(terminal::ClearType::CurrentLine),
815+
cursor::MoveToColumn(0),
816+
)?;
817+
}
816818
}
817819

818820
let (context, report, display_err_message) = match err {
@@ -1873,7 +1875,9 @@ impl ChatSession {
18731875

18741876
queue!(self.stderr, style::SetForegroundColor(Color::Magenta))?;
18751877
queue!(self.stderr, style::SetForegroundColor(Color::Reset))?;
1876-
queue!(self.stderr, cursor::Hide)?;
1878+
if !self.quiet {
1879+
queue!(self.stderr, cursor::Hide)?;
1880+
}
18771881

18781882
if self.interactive {
18791883
self.spinner = Some(Spinner::new(Spinners::Dots, "Thinking...".to_owned()));
@@ -1940,6 +1944,7 @@ impl ChatSession {
19401944
.settings
19411945
.get_bool(Setting::ChatEnableNotifications)
19421946
.unwrap_or(false)
1947+
&& !self.quiet
19431948
{
19441949
play_notification_bell(!allowed);
19451950
}
@@ -2002,7 +2007,9 @@ impl ChatSession {
20022007
cursor::Show
20032008
)?;
20042009
}
2005-
execute!(self.stdout, style::Print("\n"))?;
2010+
if !self.quiet {
2011+
execute!(self.stdout, style::Print("\n"))?;
2012+
}
20062013

20072014
let tool_end_time = Instant::now();
20082015
let tool_time = tool_end_time.duration_since(tool_start);
@@ -2133,18 +2140,22 @@ impl ChatSession {
21332140
if !image_blocks.is_empty() {
21342141
let images = image_blocks.into_iter().map(|(block, _)| block).collect();
21352142
self.conversation.add_tool_results_with_images(tool_results, images);
2136-
execute!(
2137-
self.stderr,
2138-
style::SetAttribute(Attribute::Reset),
2139-
style::SetForegroundColor(Color::Reset),
2140-
style::Print("\n")
2141-
)?;
2143+
if !self.quiet {
2144+
execute!(
2145+
self.stderr,
2146+
style::SetAttribute(Attribute::Reset),
2147+
style::SetForegroundColor(Color::Reset),
2148+
style::Print("\n")
2149+
)?;
2150+
}
21422151
} else {
21432152
self.conversation.add_tool_results(tool_results);
21442153
}
21452154

21462155
execute!(self.stderr, cursor::Hide)?;
2147-
execute!(self.stderr, style::Print("\n"), style::SetAttribute(Attribute::Reset))?;
2156+
if !self.quiet {
2157+
execute!(self.stderr, style::Print("\n"), style::SetAttribute(Attribute::Reset))?;
2158+
}
21482159
if self.interactive {
21492160
self.spinner = Some(Spinner::new(Spinners::Dots, "Thinking...".to_string()));
21502161
}
@@ -2181,7 +2192,7 @@ impl ChatSession {
21812192
let mut ended = false;
21822193
let mut state = ParseState::new(
21832194
Some(self.terminal_width()),
2184-
os.database.settings.get_bool(Setting::ChatDisableMarkdownRendering),
2195+
Some(self.quiet || os.database.settings.get_bool(Setting::ChatDisableMarkdownRendering).unwrap_or(false)),
21852196
);
21862197
let mut response_prefix_printed = false;
21872198

@@ -2190,13 +2201,15 @@ impl ChatSession {
21902201

21912202
if self.spinner.is_some() {
21922203
drop(self.spinner.take());
2193-
queue!(
2194-
self.stderr,
2195-
style::SetForegroundColor(Color::Reset),
2196-
cursor::MoveToColumn(0),
2197-
cursor::Show,
2198-
terminal::Clear(terminal::ClearType::CurrentLine),
2199-
)?;
2204+
if !self.quiet {
2205+
queue!(
2206+
self.stderr,
2207+
style::SetForegroundColor(Color::Reset),
2208+
cursor::MoveToColumn(0),
2209+
cursor::Show,
2210+
terminal::Clear(terminal::ClearType::CurrentLine),
2211+
)?;
2212+
}
22002213
}
22012214

22022215
loop {
@@ -2207,7 +2220,9 @@ impl ChatSession {
22072220
parser::ResponseEvent::ToolUseStart { name } => {
22082221
// We need to flush the buffer here, otherwise text will not be
22092222
// printed while we are receiving tool use events.
2210-
buf.push('\n');
2223+
if !self.quiet {
2224+
buf.push('\n');
2225+
}
22112226
tool_name_being_recvd = Some(name);
22122227
},
22132228
parser::ResponseEvent::AssistantText(text) => {
@@ -2280,7 +2295,9 @@ impl ChatSession {
22802295
duration.as_secs()
22812296
);
22822297

2283-
execute!(self.stderr, cursor::Hide)?;
2298+
if !self.quiet {
2299+
execute!(self.stderr, cursor::Hide)?;
2300+
}
22842301
self.spinner = Some(Spinner::new(Spinners::Dots, "Dividing up the work...".to_string()));
22852302

22862303
// For stream timeouts, we'll tell the model to try and split its response into
@@ -2370,12 +2387,14 @@ impl ChatSession {
23702387

23712388
if tool_name_being_recvd.is_none() && !buf.is_empty() && self.spinner.is_some() {
23722389
drop(self.spinner.take());
2373-
queue!(
2374-
self.stderr,
2375-
terminal::Clear(terminal::ClearType::CurrentLine),
2376-
cursor::MoveToColumn(0),
2377-
cursor::Show
2378-
)?;
2390+
if !self.quiet {
2391+
queue!(
2392+
self.stderr,
2393+
terminal::Clear(terminal::ClearType::CurrentLine),
2394+
cursor::MoveToColumn(0),
2395+
cursor::Show
2396+
)?;
2397+
}
23792398
}
23802399

23812400
// Print the response for normal cases
@@ -2401,7 +2420,9 @@ impl ChatSession {
24012420

24022421
// Set spinner after showing all of the assistant text content so far.
24032422
if tool_name_being_recvd.is_some() {
2404-
queue!(self.stderr, cursor::Hide)?;
2423+
if !self.quiet {
2424+
queue!(self.stderr, cursor::Hide)?;
2425+
}
24052426
if self.interactive {
24062427
self.spinner = Some(Spinner::new(Spinners::Dots, "Thinking...".to_string()));
24072428
}
@@ -2413,12 +2434,15 @@ impl ChatSession {
24132434
.settings
24142435
.get_bool(Setting::ChatEnableNotifications)
24152436
.unwrap_or(false)
2437+
&& !self.quiet
24162438
{
24172439
// For final responses (no tools suggested), always play the bell
24182440
play_notification_bell(tool_uses.is_empty());
24192441
}
24202442

2421-
queue!(self.stderr, style::ResetColor, style::SetAttribute(Attribute::Reset))?;
2443+
if !self.quiet {
2444+
queue!(self.stderr, style::ResetColor, style::SetAttribute(Attribute::Reset))?;
2445+
}
24222446
execute!(self.stdout, style::Print("\n"))?;
24232447

24242448
for (i, citation) in &state.citations {

0 commit comments

Comments
 (0)