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