@@ -105,10 +105,22 @@ impl Stage {
105105 // If output is attended, we do custom window with our own styling.
106106 // Therefore, we need to strip away any existing formatting.
107107 let stripped = strip_ansi_codes ( trimmed_line) ;
108+
109+ // Clip output to fit in terminal.
110+ //
111+ // Note this _does_not_ handle characters that expand to multiple columns,
112+ // like tabs or other fancy unicode. This is known to corrupt UI visuals. There
113+ // is no real solution to this without doing a mini terminal emulator AFAIK.
114+ // The workaround is to set VMTEST_NO_UI.
115+ let width = self . term . size_checked ( ) . map ( |( _, w) | w) . unwrap_or ( u16:: MAX ) ;
116+ let clipped = truncate_str ( & stripped, width as usize , "..." ) ;
117+
118+ // Apply styling
108119 let styled = match & custom {
109- Some ( s) => s. apply_to ( stripped ) ,
110- None => style ( stripped ) . dim ( ) ,
120+ Some ( s) => s. apply_to ( clipped ) ,
121+ None => style ( clipped ) . dim ( ) ,
111122 } ;
123+
112124 styled. to_string ( )
113125 } else {
114126 // If output is not attended, we do pass through
@@ -118,16 +130,9 @@ impl Stage {
118130 // Unwrap should never fail b/c we're sizing with `min()`
119131 let window = self . lines . windows ( self . window_size ( ) ) . last ( ) . unwrap ( ) ;
120132
121- // Get terminal width, if any
122- let width = match self . term . size_checked ( ) {
123- Some ( ( _, w) ) => w,
124- _ => u16:: MAX ,
125- } ;
126-
127133 // Print visible lines
128134 for line in window {
129- let clipped = truncate_str ( line, width as usize - 3 , "..." ) ;
130- self . term . write_line ( & format ! ( "{}" , clipped) ) . unwrap ( ) ;
135+ self . term . write_line ( line) . unwrap ( ) ;
131136 }
132137 }
133138
0 commit comments