@@ -55,7 +55,7 @@ pub struct Buffer {
5555 raw_buffer : Vec < u8 > ,
5656 // Time-tagged indexes into `raw_buffer`, from each input from the port.
5757 buffer_timestamps : Vec < ( usize , DateTime < Local > ) > ,
58- lines : Vec < BufLine > ,
58+ port_lines : Vec < BufLine > ,
5959 user_lines : Vec < BufLine > ,
6060 last_line_completed : bool ,
6161
@@ -106,7 +106,7 @@ impl Buffer {
106106 Self {
107107 raw_buffer : Vec :: with_capacity ( 1024 ) ,
108108 buffer_timestamps : Vec :: with_capacity ( 1024 ) ,
109- lines : Vec :: with_capacity ( 1024 ) ,
109+ port_lines : Vec :: with_capacity ( 1024 ) ,
110110 user_lines : Vec :: with_capacity ( 1024 ) ,
111111 last_terminal_size : Size :: default ( ) ,
112112 state : BufferState {
@@ -215,7 +215,7 @@ impl Buffer {
215215 }
216216
217217 if append_to_last {
218- let last_line = self . lines . last_mut ( ) . expect ( "can't append to nothing" ) ;
218+ let last_line = self . port_lines . last_mut ( ) . expect ( "can't append to nothing" ) ;
219219 let last_index = last_line. index_in_buffer ( ) ;
220220
221221 let slice = & self . raw_buffer [ last_index..start_index + trunc. len ( ) ] ;
@@ -267,7 +267,7 @@ impl Buffer {
267267 // .join("")
268268 // .escape_default()
269269 // );
270- self . lines . push ( BufLine :: new_with_line (
270+ self . port_lines . push ( BufLine :: new_with_line (
271271 line,
272272 #[ cfg( debug_assertions) ]
273273 orig,
@@ -313,7 +313,7 @@ impl Buffer {
313313 }
314314
315315 // let _ = std::mem::take(&mut self.lines);
316- self . lines . clear ( ) ;
316+ self . port_lines . clear ( ) ;
317317
318318 // Taking these variables out of `self` temporarily to allow running &mut self methods while holding
319319 // references to these.
@@ -341,8 +341,9 @@ impl Buffer {
341341 // If a user line isn't visible, ignore it when taking external new-lines into account.
342342 . filter ( |b| user_echo. filter_user_line ( b) )
343343 . map ( |b| ( b. raw_buffer_index , b. timestamp , true ) ) ,
344- |device, user| match device. 0 . cmp ( & user. 0 ) {
345- Ordering :: Equal => device. 1 <= user. 1 ,
344+ // Interleaving by sorting in order of raw_buffer_index, if they're equal, then whichever has a sooner timestamp.
345+ |port, user| match port. 0 . cmp ( & user. 0 ) {
346+ Ordering :: Equal => port. 1 <= user. 1 ,
346347 Ordering :: Less => true ,
347348 Ordering :: Greater => false ,
348349 } ,
@@ -418,7 +419,7 @@ impl Buffer {
418419
419420 /// Updates each BufLine's render height with the new terminal width, returning the sum total at the end
420421 pub fn update_wrapped_line_heights ( & mut self ) -> usize {
421- self . lines . iter_mut ( ) . fold ( 0 , |total, l| {
422+ self . port_lines . iter_mut ( ) . fold ( 0 , |total, l| {
422423 let new_height = l. update_line_height (
423424 self . last_terminal_size . width ,
424425 self . state . timestamps_visible ,
@@ -448,13 +449,18 @@ impl Buffer {
448449 }
449450 fn buflines_iter ( & self ) -> impl Iterator < Item = & BufLine > {
450451 if self . state . user_echo_input == UserEcho :: None {
451- Either :: Left ( self . lines . iter ( ) )
452+ Either :: Left ( self . port_lines . iter ( ) )
452453 } else {
453- Either :: Right ( interleave (
454- self . lines . iter ( ) ,
454+ Either :: Right ( interleave_by (
455+ self . port_lines . iter ( ) ,
455456 self . user_lines
456457 . iter ( )
457458 . filter ( |l| self . state . user_echo_input . filter_user_line ( l) ) ,
459+ |port, user| match port. raw_buffer_index . cmp ( & user. raw_buffer_index ) {
460+ Ordering :: Equal => port. timestamp <= user. timestamp ,
461+ Ordering :: Less => true ,
462+ Ordering :: Greater => false ,
463+ } ,
458464 ) )
459465 }
460466 }
@@ -488,9 +494,9 @@ impl Buffer {
488494 . enumerate ( )
489495 {
490496 current_line_index = index;
491- current_line_height = entries_lines;
497+ current_line_height = entries_lines as usize ;
492498
493- lines_from_top += entries_lines;
499+ lines_from_top += entries_lines as usize ;
494500 if lines_from_top > vert_scroll {
495501 break ;
496502 }
@@ -578,7 +584,7 @@ impl Buffer {
578584 }
579585 }
580586 pub fn clear ( & mut self ) {
581- self . lines . clear ( ) ;
587+ self . port_lines . clear ( ) ;
582588 self . buffer_timestamps . clear ( ) ;
583589 self . user_lines . clear ( ) ;
584590 self . raw_buffer . clear ( ) ;
@@ -650,14 +656,16 @@ impl Buffer {
650656 /// taking into account if text wrapping is enabled or not.
651657 pub fn combined_height ( & self ) -> usize {
652658 if self . state . text_wrapping {
653- self . buflines_iter ( ) . map ( |l| l. get_line_height ( ) ) . sum ( )
659+ self . buflines_iter ( )
660+ . map ( |l| l. get_line_height ( ) as usize )
661+ . sum ( )
654662 } else {
655663 self . buflines_iter ( ) . count ( )
656664 }
657665 }
658666
659667 pub fn port_lines_len ( & self ) -> usize {
660- self . lines . len ( )
668+ self . port_lines . len ( )
661669 }
662670
663671 pub fn update_terminal_size (
0 commit comments