Skip to content

Commit c0f1f10

Browse files
committed
ui: Do not clip strings for unattended output
String clipping is only useful if we're rendering the UI. If output is unattended or user has requested UI disabled, no need to clip output.
1 parent d18deae commit c0f1f10

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/ui.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,22 @@ impl Stage {
106106
// If UI is enabled, we do custom window with our own styling.
107107
// Therefore, we need to strip away any existing formatting.
108108
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
109120
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(),
112123
};
124+
113125
styled.to_string()
114126
} else {
115127
// If output is not attended, we do pass through
@@ -119,16 +131,9 @@ impl Stage {
119131
// Unwrap should never fail b/c we're sizing with `min()`
120132
let window = self.lines.windows(self.window_size()).last().unwrap();
121133

122-
// Get terminal width, if any
123-
let width = match self.term.size_checked() {
124-
Some((_, w)) => w,
125-
_ => u16::MAX,
126-
};
127-
128134
// Print visible lines
129135
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();
132137
}
133138
}
134139

0 commit comments

Comments
 (0)