Skip to content

Commit 5c91b63

Browse files
committed
feat: disable text styling in --no-interactive mode
Automatically partially disable ANSI color codes and styling when running in non-interactive mode. - Add a session-scoped enable_styling flag to ChatSession - Create conditional styling macros (execute_conditional!, queue_conditional!) - Implement an IsStyling trait for crossterm styling commands - Remove the response prefix ("> ") in non-interactive mode - Add a raw text output path that bypasses the markdown parser when styling is disabled - Text styling is automatically disabled when the --no-interactive flag is used
1 parent 23331b8 commit 5c91b63

File tree

4 files changed

+401
-94
lines changed

4 files changed

+401
-94
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ use std::collections::{
66
use std::io::Write;
77
use std::sync::atomic::Ordering;
88

9+
use crossterm::style;
910
use crossterm::style::Color;
10-
use crossterm::{
11-
execute,
12-
style,
13-
};
1411
use serde::{
1512
Deserialize,
1613
Serialize,
@@ -64,6 +61,7 @@ use crate::cli::agent::hook::{
6461
HookTrigger,
6562
};
6663
use crate::cli::chat::ChatError;
64+
use crate::execute_conditional;
6765
use crate::mcp_client::Prompt;
6866
use crate::os::Os;
6967

@@ -332,6 +330,7 @@ impl ConversationState {
332330
&mut self,
333331
os: &Os,
334332
stderr: &mut impl Write,
333+
enable_syling: bool,
335334
run_perprompt_hooks: bool,
336335
) -> Result<FigConversationState, ChatError> {
337336
debug_assert!(self.next_message.is_some());
@@ -341,7 +340,8 @@ impl ConversationState {
341340

342341
let context = self.backend_conversation_state(os, run_perprompt_hooks, stderr).await?;
343342
if !context.dropped_context_files.is_empty() {
344-
execute!(
343+
execute_conditional!(
344+
enable_syling,
345345
stderr,
346346
style::SetForegroundColor(Color::DarkYellow),
347347
style::Print("\nSome context files are dropped due to size limit, please run "),
@@ -1069,7 +1069,7 @@ mod tests {
10691069
conversation.set_next_user_message("start".to_string()).await;
10701070
for i in 0..=(MAX_CONVERSATION_STATE_HISTORY_LEN + 100) {
10711071
let s = conversation
1072-
.as_sendable_conversation_state(&os, &mut vec![], true)
1072+
.as_sendable_conversation_state(&os, &mut vec![], true, true)
10731073
.await
10741074
.unwrap();
10751075
assert_conversation_state_invariants(s, i);
@@ -1097,7 +1097,7 @@ mod tests {
10971097
conversation.set_next_user_message("start".to_string()).await;
10981098
for i in 0..=(MAX_CONVERSATION_STATE_HISTORY_LEN + 100) {
10991099
let s = conversation
1100-
.as_sendable_conversation_state(&os, &mut vec![], true)
1100+
.as_sendable_conversation_state(&os, &mut vec![], true, true)
11011101
.await
11021102
.unwrap();
11031103
assert_conversation_state_invariants(s, i);
@@ -1125,7 +1125,7 @@ mod tests {
11251125
conversation.set_next_user_message("start".to_string()).await;
11261126
for i in 0..=(MAX_CONVERSATION_STATE_HISTORY_LEN + 100) {
11271127
let s = conversation
1128-
.as_sendable_conversation_state(&os, &mut vec![], true)
1128+
.as_sendable_conversation_state(&os, &mut vec![], true, true)
11291129
.await
11301130
.unwrap();
11311131
assert_conversation_state_invariants(s, i);
@@ -1181,7 +1181,7 @@ mod tests {
11811181
conversation.set_next_user_message("start".to_string()).await;
11821182
for i in 0..=(MAX_CONVERSATION_STATE_HISTORY_LEN + 100) {
11831183
let s = conversation
1184-
.as_sendable_conversation_state(&os, &mut vec![], true)
1184+
.as_sendable_conversation_state(&os, &mut vec![], true, true)
11851185
.await
11861186
.unwrap();
11871187

0 commit comments

Comments
 (0)