Skip to content

Commit 538b074

Browse files
authored
fix(panoramic): prevent TUI status wrapping (#1675)
## Summary - Prevent the panoramic TUI status bar from wrapping onto additional terminal lines. - Truncate the active-test portion to fit the current terminal width. - Avoid stale wrapped status text being left behind before failure output. ## Test plan - cargo check -p panoramic - make fmt - pre-commit checks from git commit hook Co-authored-by: travis.thieman <travis.thieman@datadoghq.com>
1 parent 6273cc1 commit 538b074

1 file changed

Lines changed: 53 additions & 3 deletions

File tree

  • bin/correctness/panoramic/src

bin/correctness/panoramic/src/tui.rs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,14 @@ impl Tui {
252252
};
253253

254254
let elapsed_str = format!(" ({:.1}s)", elapsed.as_secs_f64());
255+
let status = truncate_status_bar(&progress, &active, &elapsed_str);
255256

256257
write!(
257258
stdout,
258259
"{}{}{}",
259-
progress.cyan().bold(),
260-
active.yellow(),
261-
elapsed_str.dimmed()
260+
status.progress.cyan().bold(),
261+
status.active.yellow(),
262+
status.elapsed.dimmed()
262263
)?;
263264

264265
Ok(())
@@ -311,6 +312,55 @@ impl Drop for Tui {
311312
}
312313
}
313314

315+
struct StatusBar {
316+
progress: String,
317+
active: String,
318+
elapsed: String,
319+
}
320+
321+
fn truncate_status_bar(progress: &str, active: &str, elapsed: &str) -> StatusBar {
322+
let Ok((columns, _)) = terminal::size() else {
323+
return StatusBar {
324+
progress: progress.to_string(),
325+
active: active.to_string(),
326+
elapsed: elapsed.to_string(),
327+
};
328+
};
329+
330+
let max_width = usize::from(columns);
331+
let fixed_width = progress.chars().count() + elapsed.chars().count();
332+
let active = if fixed_width >= max_width {
333+
String::new()
334+
} else {
335+
truncate_to_width(active, max_width - fixed_width)
336+
};
337+
338+
StatusBar {
339+
progress: progress.to_string(),
340+
active,
341+
elapsed: elapsed.to_string(),
342+
}
343+
}
344+
345+
fn truncate_to_width(value: &str, max_width: usize) -> String {
346+
let width = value.chars().count();
347+
if width <= max_width {
348+
return value.to_string();
349+
}
350+
351+
if max_width == 0 {
352+
return String::new();
353+
}
354+
355+
if max_width == 1 {
356+
return "…".to_string();
357+
}
358+
359+
let mut truncated = value.chars().take(max_width - 1).collect::<String>();
360+
truncated.push('…');
361+
truncated
362+
}
363+
314364
/// Run the TUI event consumer.
315365
///
316366
/// This function consumes test events from the channel and renders them to the terminal.

0 commit comments

Comments
 (0)