@@ -39,6 +39,7 @@ use clap::{
3939 Args ,
4040 CommandFactory ,
4141 Parser ,
42+ ValueEnum ,
4243} ;
4344use cli:: compact:: CompactStrategy ;
4445use cli:: model:: {
@@ -189,6 +190,16 @@ pub const EXTRA_HELP: &str = color_print::cstr! {"
189190 <black!>Change using: q settings chat.skimCommandKey x</black!>
190191" } ;
191192
193+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , ValueEnum ) ]
194+ pub enum WrapMode {
195+ /// Always wrap at terminal width
196+ Always ,
197+ /// Never wrap (raw output)
198+ Never ,
199+ /// Auto-detect based on output target (default)
200+ Auto ,
201+ }
202+
192203#[ derive( Debug , Clone , PartialEq , Eq , Default , Args ) ]
193204pub struct ChatArgs {
194205 /// Resumes the previous conversation from this directory.
@@ -212,6 +223,9 @@ pub struct ChatArgs {
212223 pub no_interactive : bool ,
213224 /// The first question to ask
214225 pub input : Option < String > ,
226+ /// Control line wrapping behavior (default: auto-detect)
227+ #[ arg( short = 'w' , long, value_enum) ]
228+ pub wrap : Option < WrapMode > ,
215229}
216230
217231impl ChatArgs {
@@ -388,6 +402,7 @@ impl ChatArgs {
388402 tool_config,
389403 !self . no_interactive ,
390404 mcp_enabled,
405+ self . wrap ,
391406 )
392407 . await ?
393408 . spawn ( os)
@@ -597,6 +612,7 @@ pub struct ChatSession {
597612 interactive : bool ,
598613 inner : Option < ChatState > ,
599614 ctrlc_rx : broadcast:: Receiver < ( ) > ,
615+ wrap : Option < WrapMode > ,
600616}
601617
602618impl ChatSession {
@@ -616,6 +632,7 @@ impl ChatSession {
616632 tool_config : HashMap < String , ToolSpec > ,
617633 interactive : bool ,
618634 mcp_enabled : bool ,
635+ wrap : Option < WrapMode > ,
619636 ) -> Result < Self > {
620637 // Reload prior conversation
621638 let mut existing_conversation = false ;
@@ -707,6 +724,7 @@ impl ChatSession {
707724 interactive,
708725 inner : Some ( ChatState :: default ( ) ) ,
709726 ctrlc_rx,
727+ wrap,
710728 } )
711729 }
712730
@@ -2395,8 +2413,20 @@ impl ChatSession {
23952413 let mut buf = String :: new ( ) ;
23962414 let mut offset = 0 ;
23972415 let mut ended = false ;
2416+ let terminal_width = match self . wrap {
2417+ Some ( WrapMode :: Never ) => None ,
2418+ Some ( WrapMode :: Always ) => Some ( self . terminal_width ( ) ) ,
2419+ Some ( WrapMode :: Auto ) | None => {
2420+ if std:: io:: stdout ( ) . is_terminal ( ) {
2421+ Some ( self . terminal_width ( ) )
2422+ } else {
2423+ None
2424+ }
2425+ } ,
2426+ } ;
2427+
23982428 let mut state = ParseState :: new (
2399- Some ( self . terminal_width ( ) ) ,
2429+ terminal_width,
24002430 os. database . settings . get_bool ( Setting :: ChatDisableMarkdownRendering ) ,
24012431 ) ;
24022432 let mut response_prefix_printed = false ;
@@ -3458,6 +3488,7 @@ mod tests {
34583488 tool_config,
34593489 true ,
34603490 false ,
3491+ None ,
34613492 )
34623493 . await
34633494 . unwrap ( )
0 commit comments