Skip to content

Commit e3e88af

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 3a4ce34 commit e3e88af

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
@@ -807,11 +807,13 @@ impl ChatSession {
807807

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

817819
let (context, report, display_err_message) = match err {
@@ -1872,7 +1874,9 @@ impl ChatSession {
18721874

18731875
queue!(self.stderr, style::SetForegroundColor(Color::Magenta))?;
18741876
queue!(self.stderr, style::SetForegroundColor(Color::Reset))?;
1875-
queue!(self.stderr, cursor::Hide)?;
1877+
if !self.quiet {
1878+
queue!(self.stderr, cursor::Hide)?;
1879+
}
18761880

18771881
if self.interactive {
18781882
self.spinner = Some(Spinner::new(Spinners::Dots, "Thinking...".to_owned()));
@@ -1921,6 +1925,7 @@ impl ChatSession {
19211925
.settings
19221926
.get_bool(Setting::ChatEnableNotifications)
19231927
.unwrap_or(false)
1928+
&& !self.quiet
19241929
{
19251930
play_notification_bell(!allowed);
19261931
}
@@ -1983,7 +1988,9 @@ impl ChatSession {
19831988
cursor::Show
19841989
)?;
19851990
}
1986-
execute!(self.stdout, style::Print("\n"))?;
1991+
if !self.quiet {
1992+
execute!(self.stdout, style::Print("\n"))?;
1993+
}
19871994

19881995
let tool_end_time = Instant::now();
19891996
let tool_time = tool_end_time.duration_since(tool_start);
@@ -2087,18 +2094,22 @@ impl ChatSession {
20872094
if !image_blocks.is_empty() {
20882095
let images = image_blocks.into_iter().map(|(block, _)| block).collect();
20892096
self.conversation.add_tool_results_with_images(tool_results, images);
2090-
execute!(
2091-
self.stderr,
2092-
style::SetAttribute(Attribute::Reset),
2093-
style::SetForegroundColor(Color::Reset),
2094-
style::Print("\n")
2095-
)?;
2097+
if !self.quiet {
2098+
execute!(
2099+
self.stderr,
2100+
style::SetAttribute(Attribute::Reset),
2101+
style::SetForegroundColor(Color::Reset),
2102+
style::Print("\n")
2103+
)?;
2104+
}
20962105
} else {
20972106
self.conversation.add_tool_results(tool_results);
20982107
}
20992108

21002109
execute!(self.stderr, cursor::Hide)?;
2101-
execute!(self.stderr, style::Print("\n"), style::SetAttribute(Attribute::Reset))?;
2110+
if !self.quiet {
2111+
execute!(self.stderr, style::Print("\n"), style::SetAttribute(Attribute::Reset))?;
2112+
}
21022113
if self.interactive {
21032114
self.spinner = Some(Spinner::new(Spinners::Dots, "Thinking...".to_string()));
21042115
}
@@ -2135,7 +2146,7 @@ impl ChatSession {
21352146
let mut ended = false;
21362147
let mut state = ParseState::new(
21372148
Some(self.terminal_width()),
2138-
os.database.settings.get_bool(Setting::ChatDisableMarkdownRendering),
2149+
Some(self.quiet || os.database.settings.get_bool(Setting::ChatDisableMarkdownRendering).unwrap_or(false)),
21392150
);
21402151
let mut response_prefix_printed = false;
21412152

@@ -2144,13 +2155,15 @@ impl ChatSession {
21442155

21452156
if self.spinner.is_some() {
21462157
drop(self.spinner.take());
2147-
queue!(
2148-
self.stderr,
2149-
style::SetForegroundColor(Color::Reset),
2150-
cursor::MoveToColumn(0),
2151-
cursor::Show,
2152-
terminal::Clear(terminal::ClearType::CurrentLine),
2153-
)?;
2158+
if !self.quiet {
2159+
queue!(
2160+
self.stderr,
2161+
style::SetForegroundColor(Color::Reset),
2162+
cursor::MoveToColumn(0),
2163+
cursor::Show,
2164+
terminal::Clear(terminal::ClearType::CurrentLine),
2165+
)?;
2166+
}
21542167
}
21552168

21562169
loop {
@@ -2161,7 +2174,9 @@ impl ChatSession {
21612174
parser::ResponseEvent::ToolUseStart { name } => {
21622175
// We need to flush the buffer here, otherwise text will not be
21632176
// printed while we are receiving tool use events.
2164-
buf.push('\n');
2177+
if !self.quiet {
2178+
buf.push('\n');
2179+
}
21652180
tool_name_being_recvd = Some(name);
21662181
},
21672182
parser::ResponseEvent::AssistantText(text) => {
@@ -2234,7 +2249,9 @@ impl ChatSession {
22342249
duration.as_secs()
22352250
);
22362251

2237-
execute!(self.stderr, cursor::Hide)?;
2252+
if !self.quiet {
2253+
execute!(self.stderr, cursor::Hide)?;
2254+
}
22382255
self.spinner = Some(Spinner::new(Spinners::Dots, "Dividing up the work...".to_string()));
22392256

22402257
// For stream timeouts, we'll tell the model to try and split its response into
@@ -2324,12 +2341,14 @@ impl ChatSession {
23242341

23252342
if tool_name_being_recvd.is_none() && !buf.is_empty() && self.spinner.is_some() {
23262343
drop(self.spinner.take());
2327-
queue!(
2328-
self.stderr,
2329-
terminal::Clear(terminal::ClearType::CurrentLine),
2330-
cursor::MoveToColumn(0),
2331-
cursor::Show
2332-
)?;
2344+
if !self.quiet {
2345+
queue!(
2346+
self.stderr,
2347+
terminal::Clear(terminal::ClearType::CurrentLine),
2348+
cursor::MoveToColumn(0),
2349+
cursor::Show
2350+
)?;
2351+
}
23332352
}
23342353

23352354
// Print the response for normal cases
@@ -2355,7 +2374,9 @@ impl ChatSession {
23552374

23562375
// Set spinner after showing all of the assistant text content so far.
23572376
if tool_name_being_recvd.is_some() {
2358-
queue!(self.stderr, cursor::Hide)?;
2377+
if !self.quiet {
2378+
queue!(self.stderr, cursor::Hide)?;
2379+
}
23592380
if self.interactive {
23602381
self.spinner = Some(Spinner::new(Spinners::Dots, "Thinking...".to_string()));
23612382
}
@@ -2367,12 +2388,15 @@ impl ChatSession {
23672388
.settings
23682389
.get_bool(Setting::ChatEnableNotifications)
23692390
.unwrap_or(false)
2391+
&& !self.quiet
23702392
{
23712393
// For final responses (no tools suggested), always play the bell
23722394
play_notification_bell(tool_uses.is_empty());
23732395
}
23742396

2375-
queue!(self.stderr, style::ResetColor, style::SetAttribute(Attribute::Reset))?;
2397+
if !self.quiet {
2398+
queue!(self.stderr, style::ResetColor, style::SetAttribute(Attribute::Reset))?;
2399+
}
23762400
execute!(self.stdout, style::Print("\n"))?;
23772401

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

0 commit comments

Comments
 (0)