Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adjust task and waker panel for long names #527

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions tokio-console/src/view/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
help::HelpText,
},
};
use ratatui::widgets::Wrap;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: merge this with the other ratatui imports ok the next line.

use ratatui::{
layout::{self, Layout},
text::{Span, Spans, Text},
Expand Down Expand Up @@ -131,8 +132,8 @@ impl TaskView {
.direction(layout::Direction::Horizontal)
.constraints(
[
layout::Constraint::Percentage(50),
layout::Constraint::Percentage(50),
layout::Constraint::Percentage(60),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might want something more dynamic than this. What do you think?

layout::Constraint::Percentage(40),
]
.as_ref(),
)
Expand All @@ -156,16 +157,8 @@ impl TaskView {
]));

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)]));
overview.push(Spans::from(vec![bold(title), Span::raw(task.location())]));

let total = task.total(now);

Expand Down Expand Up @@ -195,21 +188,21 @@ impl TaskView {
Span::from(format!("{})", task.waker_drops())),
])];

let mut wakeups = vec![
let wakeups = vec![
bold("Woken: "),
Span::from(format!("{} times", task.wakes())),
];

waker_stats.push(Spans::from(wakeups));

// If the task has been woken, add the time since wake to its stats as well.
if let Some(since) = task.since_wake(now) {
wakeups.reserve(3);
wakeups.push(Span::raw(", "));
wakeups.push(bold("last woken:"));
wakeups.push(Span::from(format!(" {:?} ago", since)));
waker_stats.push(Spans::from(vec![
bold("Last woken:"),
Span::from(format!(" {:?} ago", since)),
]));
}

waker_stats.push(Spans::from(wakeups));

if task.self_wakes() > 0 {
waker_stats.push(Spans::from(vec![
bold("Self Wakes: "),
Expand All @@ -229,7 +222,9 @@ impl TaskView {
frame.render_widget(warnings, warnings_area);
}

let task_widget = Paragraph::new(overview).block(styles.border_block().title("Task"));
let task_widget = Paragraph::new(overview)
.wrap(Wrap { trim: true })
.block(styles.border_block().title("Task"));
let wakers_widget = Paragraph::new(waker_stats).block(styles.border_block().title("Waker"));

let poll_percentiles_title = "Poll Times Percentiles";
Expand Down
Loading