@@ -366,6 +366,7 @@ impl Buffer {
366366 self . raw . inner . len ( ) , // .max(1)
367367 self . last_terminal_size . width ,
368368 & self . rendering ,
369+ & self . line_ending ,
369370 now,
370371 LineType :: User {
371372 is_bytes : true ,
@@ -438,6 +439,7 @@ impl Buffer {
438439 self . raw . inner . len ( ) , // .max(1)
439440 self . last_terminal_size . width ,
440441 & self . rendering ,
442+ & self . line_ending ,
441443 now,
442444 LineType :: User {
443445 is_bytes : false ,
@@ -484,6 +486,8 @@ impl Buffer {
484486 return ;
485487 }
486488
489+ let this_rx_completed = self . raw . inner . has_line_ending ( & self . line_ending ) ;
490+
487491 if append_to_last {
488492 let last_line = self
489493 . styled_lines
@@ -492,18 +496,19 @@ impl Buffer {
492496 . expect ( "can't append to nothing" ) ;
493497 let last_index = last_line. index_in_buffer ( ) ;
494498
495- let slice = & self . raw . inner [ last_index..start_index + trunc. len ( ) ] ;
499+ let trunc = & self . raw . inner [ last_index..start_index + trunc. len ( ) ] ;
500+ let orig = & self . raw . inner [ last_index..start_index + orig. len ( ) ] ;
496501 // info!("AAAFG: {:?}", slice);
497502 let lossy_flavor = if self . rendering . escape_invalid_bytes {
498503 LossyFlavor :: escaped_bytes_styled ( Style :: new ( ) . dark_gray ( ) )
499504 } else {
500505 LossyFlavor :: replacement_char ( )
501506 } ;
502- let mut line = match slice . into_line_lossy ( Style :: new ( ) , lossy_flavor) {
507+ let mut line = match trunc . into_line_lossy ( Style :: new ( ) , lossy_flavor) {
503508 Ok ( line) => line,
504509 Err ( _) => {
505510 error ! ( "ansi-to-tui failed to parse input! Using unstyled text." ) ;
506- Line :: from ( String :: from_utf8_lossy ( slice ) . to_string ( ) )
511+ Line :: from ( String :: from_utf8_lossy ( trunc ) . to_string ( ) )
507512 }
508513 } ;
509514 // debug!(
@@ -520,10 +525,16 @@ impl Buffer {
520525 // line.style_slice(1..3, Style::new().red().italic());
521526 // }
522527
523- let line_opt = self . color_rules . apply_onto ( slice , line) ;
528+ let line_opt = self . color_rules . apply_onto ( trunc , line) ;
524529
525530 if let Some ( line) = line_opt {
526- last_line. update_line ( line, slice, self . last_terminal_size . width , & self . rendering ) ;
531+ last_line. update_line (
532+ line,
533+ orig,
534+ self . last_terminal_size . width ,
535+ & self . rendering ,
536+ & self . line_ending ,
537+ ) ;
527538 } else {
528539 _ = self . styled_lines . rx . pop ( ) ;
529540 self . styled_lines . last_rx_completed = true ;
@@ -545,39 +556,23 @@ impl Buffer {
545556
546557 let line_opt = self . color_rules . apply_onto ( trunc, line) ;
547558
548- // if line.width() >= 5 {
549- // line.style_slice(1..3, Style::new().red().italic());
550- // }
551-
552- // if !line.is_styled() {
553- // assert!(line.spans.len() <= 1);
554- // }
555-
556- // debug!(
557- // "buf_index: {start_index}, new: {line}",
558- // line = line
559- // .spans
560- // .iter()
561- // .map(|s| s.content.as_ref())
562- // .join("")
563- // .escape_default()
564- // );
565-
566- // let line = line_opt.unwrap_or_default();
567559 if let Some ( line) = line_opt {
568560 self . styled_lines . rx . push ( BufLine :: new_with_line (
569561 line,
570562 orig,
571563 start_index,
572564 self . last_terminal_size . width ,
573565 & self . rendering ,
566+ & self . line_ending ,
574567 known_time. unwrap_or_else ( Local :: now) ,
575- LineType :: Port ,
568+ LineType :: Port {
569+ escaped_line_ending : None ,
570+ } ,
576571 ) ) ;
577572 }
578573 } ;
579- let last_rx_completed = self . raw . inner . has_line_ending ( & self . line_ending ) ;
580- self . styled_lines . last_rx_completed = last_rx_completed ;
574+
575+ self . styled_lines . last_rx_completed = this_rx_completed ;
581576 }
582577
583578 // Forced to use Vec<u8> for now
@@ -737,8 +732,9 @@ impl Buffer {
737732 let should_reconsume =
738733 changed ! ( old, new, echo_user_input) || changed ! ( old, new, escape_invalid_bytes) ;
739734
740- let should_rewrap_lines =
741- changed ! ( old, new, timestamps) || changed ! ( old, new, show_indices) ;
735+ let should_rewrap_lines = changed ! ( old, new, timestamps)
736+ || changed ! ( old, new, show_indices)
737+ || changed ! ( old, new, show_line_ending) ;
742738
743739 if changed ! ( old, new, bytes_per_line) {
744740 self . determine_bytes_per_line ( new. bytes_per_line . into ( ) ) ;
0 commit comments