Skip to content

Commit

Permalink
fix(console): make long locations readable
Browse files Browse the repository at this point in the history
This closes tokio-rs#411.
  • Loading branch information
guerinoni committed Jul 3, 2023
1 parent 27a572d commit d294a78
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tokio-console/src/view/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,17 @@ impl TaskView {
Span::raw(task.target()),
]));

overview.push(Spans::from(vec![
bold("Location: "),
Span::raw(task.location()),
]));
let title = "Location: ";
let location_max_width = stats_area[0].width as usize - 2 - title.len(); // NOTE: -2 for the border
let location = if task.location().len() > location_max_width {
let ellipsis = styles.if_utf8("\u{2026}", "...");
let start = task.location().len() - location_max_width + ellipsis.chars().count();
format!("{}{}", ellipsis, &task.location()[start..])
} else {
task.location().to_string()
};

overview.push(Spans::from(vec![bold(title), Span::raw(location)]));

let total = task.total(now);

Expand Down

0 comments on commit d294a78

Please sign in to comment.