From 20562c11f00c73d4d884c56c6bf33010765c5c08 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Fri, 2 Feb 2024 16:27:48 -0800 Subject: [PATCH] chore(deps): update ratatui to 0.26.0 This necessitated 3 changes to the codebase: - `Spans` was renamed to the more ergonomic `Line` type. - `Frame` no longer requires a backend type parameter. - `Table::new` requires a widths parameter, so we use `Table::default().rows(rows)` instead of `Table::new(rows)`. --- Cargo.lock | 169 ++++++++++++++++++++++++-- tokio-console/Cargo.toml | 4 +- tokio-console/src/conn.rs | 6 +- tokio-console/src/main.rs | 8 +- tokio-console/src/view/async_ops.rs | 12 +- tokio-console/src/view/controls.rs | 24 ++-- tokio-console/src/view/help.rs | 4 +- tokio-console/src/view/mod.rs | 4 +- tokio-console/src/view/percentiles.rs | 4 +- tokio-console/src/view/resource.rs | 20 +-- tokio-console/src/view/resources.rs | 12 +- tokio-console/src/view/table.rs | 8 +- tokio-console/src/view/task.rs | 33 +++-- tokio-console/src/view/tasks.rs | 18 +-- 14 files changed, 237 insertions(+), 89 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9fc6acbc6..7b16a0b16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,18 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.0.5" @@ -26,6 +38,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "anyhow" version = "1.0.56" @@ -184,6 +202,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" +[[package]] +name = "castaway" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a17ed5635fc8536268e5d4de1e22e81ac34419e5f052d4d51f4e01dcc263fcc" +dependencies = [ + "rustversion", +] + [[package]] name = "cc" version = "1.0.73" @@ -287,6 +314,19 @@ dependencies = [ "memchr", ] +[[package]] +name = "compact_str" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f86b9c4c00838774a6d902ef931eff7470720c51d90c2e32cfe15dc304737b3f" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "ryu", + "static_assertions", +] + [[package]] name = "concolor" version = "0.0.8" @@ -406,11 +446,11 @@ dependencies = [ [[package]] name = "crossterm" -version = "0.26.1" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" +checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "crossterm_winapi", "futures-core", "libc", @@ -686,6 +726,16 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", + "allocator-api2", +] + [[package]] name = "hdrhistogram" version = "7.5.0" @@ -830,9 +880,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.11.2", ] +[[package]] +name = "indoc" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" + [[package]] name = "instant" version = "0.1.12" @@ -882,6 +938,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.6" @@ -928,6 +993,15 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "lru" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2c024b41519440580066ba82aab04092b333e09066a5eb86c7c4890df31f22" +dependencies = [ + "hashbrown 0.14.3", +] + [[package]] name = "matchers" version = "0.1.0" @@ -1060,9 +1134,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.1" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "option-ext" @@ -1115,6 +1189,12 @@ dependencies = [ "windows-sys 0.34.0", ] +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -1283,13 +1363,20 @@ dependencies = [ [[package]] name = "ratatui" -version = "0.20.1" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc0d032bccba900ee32151ec0265667535c230169f5a011154cdcd984e16829" +checksum = "154b85ef15a5d1719bcaa193c3c81fe645cd120c156874cd660fe49fd21d1373" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "cassowary", + "compact_str", "crossterm", + "indoc", + "itertools 0.12.1", + "lru", + "paste", + "stability", + "strum", "unicode-segmentation", "unicode-width", ] @@ -1586,12 +1673,50 @@ dependencies = [ "winapi", ] +[[package]] +name = "stability" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd1b177894da2a2d9120208c3386066af06a488255caabc5de8ddca22dbc3ce" +dependencies = [ + "quote", + "syn 1.0.90", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strum" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "723b93e8addf9aa965ebe2d11da6d7540fa2283fcea14b3371ff055f7ba13f5f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a3417fc93d76740d974a01654a09777cb500428cc874ca9f45edfe0c4d4cd18" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.33", +] + [[package]] name = "syn" version = "1.0.90" @@ -2052,6 +2177,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "wait-timeout" version = "0.2.0" @@ -2301,3 +2432,23 @@ name = "yansi" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.33", +] diff --git a/tokio-console/Cargo.toml b/tokio-console/Cargo.toml index ca58b68f2..4f33e9e91 100644 --- a/tokio-console/Cargo.toml +++ b/tokio-console/Cargo.toml @@ -35,13 +35,13 @@ clap_complete = "~4.1.6" tokio = { version = "1", features = ["full", "rt-multi-thread"] } tonic = { version = "0.10", features = ["transport"] } futures = "0.3" -ratatui = { version = "0.20.1", default-features = false, features = ["crossterm"] } +ratatui = { version = "0.26.0", default-features = false, features = ["crossterm"] } tower = "0.4.12" tracing = "0.1" tracing-subscriber = { version = "0.3" } tracing-journald = { version = "0.2", optional = true } prost-types = "0.12" -crossterm = { version = "0.26.1", features = ["event-stream"] } +crossterm = { version = "0.27.0", features = ["event-stream"] } color-eyre = { version = "0.6", features = ["issue-url"] } hdrhistogram = { version = "7.3.0", default-features = false, features = ["serialization"] } # Keep this in sync with the version from `tonic`. diff --git a/tokio-console/src/conn.rs b/tokio-console/src/conn.rs index 8cfd4bf51..471035c19 100644 --- a/tokio-console/src/conn.rs +++ b/tokio-console/src/conn.rs @@ -183,10 +183,10 @@ impl Connection { } } - pub fn render(&self, styles: &crate::view::Styles) -> ratatui::text::Spans { + pub fn render(&self, styles: &crate::view::Styles) -> ratatui::text::Line { use ratatui::{ style::{Color, Modifier}, - text::{Span, Spans}, + text::{Line, Span}, }; let state = match self.state { State::Connected { .. } => Span::styled( @@ -202,7 +202,7 @@ impl Connection { styles.fg(Color::Yellow).add_modifier(Modifier::BOLD), ), }; - Spans::from(vec![ + Line::from(vec![ Span::raw("connection: "), Span::raw(self.target.to_string()), Span::raw(" "), diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index 4f99ee71a..7e9c78a1b 100644 --- a/tokio-console/src/main.rs +++ b/tokio-console/src/main.rs @@ -9,7 +9,7 @@ use futures::{ use ratatui::{ layout::{Constraint, Direction, Layout}, style::Color, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Paragraph, Wrap}, }; use tokio::sync::{mpsc, watch}; @@ -147,7 +147,7 @@ async fn main() -> color_eyre::Result<()> { let mut header_text = conn.render(&view.styles); if state.is_paused() { header_text - .0 + .spans .push(Span::styled(" PAUSED", view.styles.fg(Color::Red))); } let dropped_async_ops_state = state.async_ops_state().dropped_events(); @@ -164,13 +164,13 @@ async fn main() -> color_eyre::Result<()> { if dropped_resources_state > 0 { dropped_texts.push(format!("{} resources", dropped_resources_state)) } - header_text.0.push(Span::styled( + header_text.spans.push(Span::styled( format!(" dropped: {}", dropped_texts.join(", ")), view.styles.fg(Color::Red), )); } let header = Paragraph::new(header_text).wrap(Wrap { trim: true }); - let view_controls = Paragraph::new(Spans::from(vec![ + let view_controls = Paragraph::new(Line::from(vec![ Span::raw("views: "), bold("t"), Span::raw(" = tasks, "), diff --git a/tokio-console/src/view/async_ops.rs b/tokio-console/src/view/async_ops.rs index 380799b8d..00dfd0c1b 100644 --- a/tokio-console/src/view/async_ops.rs +++ b/tokio-console/src/view/async_ops.rs @@ -16,7 +16,7 @@ use crate::{ use ratatui::{ layout, style::{self, Color, Style}, - text::Spans, + text::Line, widgets::{Cell, Row, Table}, }; @@ -57,10 +57,10 @@ impl TableList<9> for AsyncOpsTable { Self::HEADER[8].len() + 1, ]; - fn render( + fn render( table_list_state: &mut TableListState, styles: &view::Styles, - frame: &mut ratatui::terminal::Frame, + frame: &mut ratatui::terminal::Frame, area: layout::Rect, state: &mut State, ctx: Self::Context, @@ -145,7 +145,7 @@ impl TableList<9> for AsyncOpsTable { dur_cell(async_op.busy(now)), dur_cell(async_op.idle(now)), Cell::from(polls_width.update_str(async_op.total_polls().to_string())), - Cell::from(Spans::from( + Cell::from(Line::from( async_op .formatted_attributes() .iter() @@ -185,9 +185,9 @@ impl TableList<9> for AsyncOpsTable { .style(header_style); let table = if table_list_state.sort_descending { - Table::new(rows) + Table::default().rows(rows) } else { - Table::new(rows.rev()) + Table::default().rows(rows.rev()) }; let block = styles.border_block().title(vec![bold(format!( diff --git a/tokio-console/src/view/controls.rs b/tokio-console/src/view/controls.rs index bf9972532..43941cc9a 100644 --- a/tokio-console/src/view/controls.rs +++ b/tokio-console/src/view/controls.rs @@ -2,7 +2,7 @@ use crate::view::{self, bold}; use ratatui::{ layout, - text::{Span, Spans, Text}, + text::{Line, Span, Text}, widgets::{Paragraph, Widget}, }; @@ -41,17 +41,17 @@ impl Controls { spans_controls.extend(view_controls.iter().map(|c| c.to_spans(styles, 0))); spans_controls.extend(UNIVERSAL_CONTROLS.iter().map(|c| c.to_spans(styles, 0))); - let mut lines = vec![Spans::from(vec![Span::from("controls: ")])]; + let mut lines = vec![Line::from(vec![Span::from("controls: ")])]; let mut current_line = lines.last_mut().expect("This vector is never empty"); let separator = Span::from(", "); let controls_count: usize = spans_controls.len(); - for (idx, spans) in spans_controls.into_iter().enumerate() { + for (idx, line) in spans_controls.into_iter().enumerate() { // If this is the first item on this line - or first item on the // first line, then always include it - even if it goes beyond the // line width, not much we can do anyway. if idx == 0 || current_line.width() == 0 { - current_line.0.extend(spans.0); + current_line.spans.extend(line.spans); continue; } @@ -66,7 +66,7 @@ impl Controls { let total_width = current_line.width() + separator.width() - + spans.width() + + line.width() + needed_trailing_separator_width; // If the current item fits on this line, append it. @@ -74,11 +74,11 @@ impl Controls { // width in the previous loop iteration - and then create a new // line for the current item. if total_width <= area.width as usize { - current_line.0.push(separator.clone()); - current_line.0.extend(spans.0); + current_line.spans.push(separator.clone()); + current_line.spans.extend(line.spans); } else { - current_line.0.push(separator.clone()); - lines.push(spans); + current_line.spans.push(separator.clone()); + lines.push(line); current_line = lines.last_mut().expect("This vector is never empty"); } } @@ -106,7 +106,7 @@ pub(crate) fn controls_paragraph<'a>( styles: &view::Styles, ) -> Paragraph<'a> { let mut spans = Vec::with_capacity(1 + view_controls.len() + UNIVERSAL_CONTROLS.len()); - spans.push(Spans::from(vec![Span::raw("controls:")])); + spans.push(Line::from(vec![Span::raw("controls:")])); spans.extend(view_controls.iter().map(|c| c.to_spans(styles, 2))); spans.extend(UNIVERSAL_CONTROLS.iter().map(|c| c.to_spans(styles, 2))); @@ -137,7 +137,7 @@ pub(crate) struct KeyDisplay { } impl ControlDisplay { - pub(crate) fn to_spans(&self, styles: &view::Styles, indent: usize) -> Spans<'static> { + pub(crate) fn to_spans(&self, styles: &view::Styles, indent: usize) -> Line<'static> { let mut spans = Vec::new(); spans.push(Span::from(" ".repeat(indent))); @@ -153,6 +153,6 @@ impl ControlDisplay { })); } - Spans::from(spans) + Line::from(spans) } } diff --git a/tokio-console/src/view/help.rs b/tokio-console/src/view/help.rs index de249db61..297385967 100644 --- a/tokio-console/src/view/help.rs +++ b/tokio-console/src/view/help.rs @@ -21,10 +21,10 @@ impl<'a> HelpView<'a> { } } - pub(crate) fn render( + pub(crate) fn render( &mut self, styles: &view::Styles, - frame: &mut ratatui::terminal::Frame, + frame: &mut ratatui::terminal::Frame, _area: layout::Rect, _state: &mut State, ) { diff --git a/tokio-console/src/view/mod.rs b/tokio-console/src/view/mod.rs index 1a9703000..d13211dee 100644 --- a/tokio-console/src/view/mod.rs +++ b/tokio-console/src/view/mod.rs @@ -216,9 +216,9 @@ impl View { input::is_help_toggle(event) || (self.show_help_modal && input::is_esc(event)) } - pub(crate) fn render( + pub(crate) fn render( &mut self, - frame: &mut ratatui::terminal::Frame, + frame: &mut ratatui::terminal::Frame, area: layout::Rect, state: &mut State, ) { diff --git a/tokio-console/src/view/percentiles.rs b/tokio-console/src/view/percentiles.rs index 207cc3ad7..20343c66a 100644 --- a/tokio-console/src/view/percentiles.rs +++ b/tokio-console/src/view/percentiles.rs @@ -1,7 +1,7 @@ use std::time::Duration; use ratatui::{ - text::{Spans, Text}, + text::{Line, Text}, widgets::{Paragraph, Widget}, }; @@ -51,7 +51,7 @@ impl<'a> Percentiles<'a> { .iter() .map(move |i| (*i, histogram.value_at_percentile(*i))); let percentiles = pairs.map(|pair| { - Spans::from(vec![ + Line::from(vec![ bold(format!("p{:>2}: ", pair.0)), self.styles.time_units( Duration::from_nanos(pair.1), diff --git a/tokio-console/src/view/resource.rs b/tokio-console/src/view/resource.rs index 8c85203ac..5a1554c29 100644 --- a/tokio-console/src/view/resource.rs +++ b/tokio-console/src/view/resource.rs @@ -14,7 +14,7 @@ use crate::{ use once_cell::sync::OnceCell; use ratatui::{ layout::{self, Layout}, - text::{Span, Spans, Text}, + text::{Line, Span, Text}, widgets::Paragraph, }; use std::{cell::RefCell, rc::Rc}; @@ -38,10 +38,10 @@ impl ResourceView { self.async_ops_table.update_input(event) } - pub(crate) fn render( + pub(crate) fn render( &mut self, styles: &view::Styles, - frame: &mut ratatui::terminal::Frame, + frame: &mut ratatui::terminal::Frame, area: layout::Rect, state: &mut State, ) { @@ -78,17 +78,17 @@ impl ResourceView { .split(stats_area); let overview = vec![ - Spans::from(vec![bold("ID: "), Span::raw(resource.id_str())]), - Spans::from(vec![bold("Parent ID: "), Span::raw(resource.parent())]), - Spans::from(vec![bold("Kind: "), Span::raw(resource.kind())]), - Spans::from(vec![bold("Target: "), Span::raw(resource.target())]), - Spans::from(vec![ + Line::from(vec![bold("ID: "), Span::raw(resource.id_str())]), + Line::from(vec![bold("Parent ID: "), Span::raw(resource.parent())]), + Line::from(vec![bold("Kind: "), Span::raw(resource.kind())]), + Line::from(vec![bold("Target: "), Span::raw(resource.target())]), + Line::from(vec![ bold("Type: "), Span::raw(resource.concrete_type()), Span::raw(" "), resource.type_visibility().render(styles), ]), - Spans::from(vec![bold("Location: "), Span::raw(resource.location())]), + Line::from(vec![bold("Location: "), Span::raw(resource.location())]), ]; let mut fields = Text::default(); @@ -97,7 +97,7 @@ impl ResourceView { .formatted_attributes() .iter() .cloned() - .map(Spans::from), + .map(Line::from), ); let resource_widget = diff --git a/tokio-console/src/view/resources.rs b/tokio-console/src/view/resources.rs index 124ba22d5..05a66b475 100644 --- a/tokio-console/src/view/resources.rs +++ b/tokio-console/src/view/resources.rs @@ -14,7 +14,7 @@ use crate::{ use ratatui::{ layout, style::{self, Color, Style}, - text::Spans, + text::Line, widgets::{Cell, Row, Table}, }; @@ -50,10 +50,10 @@ impl TableList<9> for ResourcesTable { Self::HEADER[8].len() + 1, ]; - fn render( + fn render( table_list_state: &mut TableListState, styles: &view::Styles, - frame: &mut ratatui::terminal::Frame, + frame: &mut ratatui::terminal::Frame, area: layout::Rect, state: &mut State, _: Self::Context, @@ -114,7 +114,7 @@ impl TableList<9> for ResourcesTable { Cell::from(type_width.update_str(resource.concrete_type()).to_owned()), Cell::from(resource.type_visibility().render(styles)), Cell::from(location_width.update_str(resource.location()).to_owned()), - Cell::from(Spans::from( + Cell::from(Line::from( resource .formatted_attributes() .iter() @@ -154,9 +154,9 @@ impl TableList<9> for ResourcesTable { .style(header_style); let table = if table_list_state.sort_descending { - Table::new(rows) + Table::default().rows(rows) } else { - Table::new(rows.rev()) + Table::default().rows(rows.rev()) }; let block = styles.border_block().title(vec![bold(format!( diff --git a/tokio-console/src/view/table.rs b/tokio-console/src/view/table.rs index 10fdd16dc..40ffc8757 100644 --- a/tokio-console/src/view/table.rs +++ b/tokio-console/src/view/table.rs @@ -23,10 +23,10 @@ pub(crate) trait TableList { const HEADER: &'static [&'static str; N]; const WIDTHS: &'static [usize; N]; - fn render( + fn render( state: &mut TableListState, styles: &view::Styles, - frame: &mut ratatui::terminal::Frame, + frame: &mut ratatui::terminal::Frame, area: layout::Rect, state: &mut state::State, cx: Self::Context, @@ -168,10 +168,10 @@ impl, const N: usize> TableListState { .unwrap_or_default() } - pub(in crate::view) fn render( + pub(in crate::view) fn render( &mut self, styles: &view::Styles, - frame: &mut ratatui::terminal::Frame, + frame: &mut ratatui::terminal::Frame, area: layout::Rect, state: &mut state::State, ctx: T::Context, diff --git a/tokio-console/src/view/task.rs b/tokio-console/src/view/task.rs index 8f3024520..316cc184c 100644 --- a/tokio-console/src/view/task.rs +++ b/tokio-console/src/view/task.rs @@ -11,7 +11,7 @@ use crate::{ }; use ratatui::{ layout::{self, Layout}, - text::{Span, Spans, Text}, + text::{Line, Span, Text}, widgets::{List, ListItem, Paragraph}, }; use std::{ @@ -35,10 +35,10 @@ impl TaskView { // TODO :D } - pub(crate) fn render( + pub(crate) fn render( &mut self, styles: &view::Styles, - frame: &mut ratatui::terminal::Frame, + frame: &mut ratatui::terminal::Frame, area: layout::Rect, now: SystemTime, ) { @@ -60,7 +60,7 @@ impl TaskView { .warnings() .iter() .map(|linter| { - ListItem::new(Text::from(Spans::from(vec![ + ListItem::new(Text::from(Line::from(vec![ styles.warning_wide(), // TODO(eliza): it would be nice to handle singular vs plural... Span::from(linter.format(task)), @@ -140,20 +140,17 @@ impl TaskView { // Just preallocate capacity for ID, name, target, total, busy, and idle. let mut overview = Vec::with_capacity(8); - overview.push(Spans::from(vec![ + overview.push(Line::from(vec![ bold("ID: "), Span::raw(format!("{} ", task.id_str())), task.state().render(styles), ])); if let Some(name) = task.name() { - overview.push(Spans::from(vec![bold("Name: "), Span::raw(name)])); + overview.push(Line::from(vec![bold("Name: "), Span::raw(name)])); } - overview.push(Spans::from(vec![ - bold("Target: "), - Span::raw(task.target()), - ])); + overview.push(Line::from(vec![bold("Target: "), Span::raw(task.target())])); let title = "Location: "; let location_max_width = stats_area[0].width as usize - 2 - title.len(); // NOTE: -2 for the border @@ -165,20 +162,20 @@ impl TaskView { task.location().to_string() }; - overview.push(Spans::from(vec![bold(title), Span::raw(location)])); + overview.push(Line::from(vec![bold(title), Span::raw(location)])); let total = task.total(now); - let dur_percent = |name: &'static str, amt: Duration| -> Spans { + let dur_percent = |name: &'static str, amt: Duration| -> Line { let percent = amt.as_secs_f64().percent_of(total.as_secs_f64()); - Spans::from(vec![ + Line::from(vec![ bold(name), styles.time_units(amt, view::DUR_LIST_PRECISION, None), Span::from(format!(" ({:.2}%)", percent)), ]) }; - overview.push(Spans::from(vec![ + overview.push(Line::from(vec![ bold("Total Time: "), styles.time_units(total, view::DUR_LIST_PRECISION, None), ])); @@ -186,7 +183,7 @@ impl TaskView { overview.push(dur_percent("Scheduled: ", task.scheduled(now))); overview.push(dur_percent("Idle: ", task.idle(now))); - let mut waker_stats = vec![Spans::from(vec![ + let mut waker_stats = vec![Line::from(vec![ bold("Current wakers: "), Span::from(format!("{} (", task.waker_count())), bold("clones: "), @@ -208,10 +205,10 @@ impl TaskView { wakeups.push(Span::from(format!(" {:?} ago", since))); } - waker_stats.push(Spans::from(wakeups)); + waker_stats.push(Line::from(wakeups)); if task.self_wakes() > 0 { - waker_stats.push(Spans::from(vec![ + waker_stats.push(Line::from(vec![ bold("Self Wakes: "), Span::from(format!( "{} times ({}%)", @@ -222,7 +219,7 @@ impl TaskView { } let mut fields = Text::default(); - fields.extend(task.formatted_fields().iter().cloned().map(Spans::from)); + fields.extend(task.formatted_fields().iter().cloned().map(Line::from)); if let Some(warnings_area) = warnings_area { let warnings = List::new(warnings).block(styles.border_block().title("Warnings")); diff --git a/tokio-console/src/view/tasks.rs b/tokio-console/src/view/tasks.rs index d6d057b24..15e8f252c 100644 --- a/tokio-console/src/view/tasks.rs +++ b/tokio-console/src/view/tasks.rs @@ -13,7 +13,7 @@ use crate::{ use ratatui::{ layout, style::{self, Color, Style}, - text::{Span, Spans, Text}, + text::{Line, Span, Text}, widgets::{self, Cell, ListItem, Row, Table}, }; @@ -45,10 +45,10 @@ impl TableList<12> for TasksTable { Self::HEADER[11].len() + 1, ]; - fn render( + fn render( table_list_state: &mut TableListState, styles: &view::Styles, - frame: &mut ratatui::terminal::Frame, + frame: &mut ratatui::terminal::Frame, area: layout::Rect, state: &mut State, _: Self::Context, @@ -112,7 +112,7 @@ impl TableList<12> for TasksTable { let warnings = if n_warnings > 0 { let n_warnings = n_warnings.to_string(); warn_width.update_len(n_warnings.len() + 2); // add 2 for the warning icon + whitespace - Cell::from(Spans::from(vec![ + Cell::from(Line::from(vec![ styles.warning_narrow(), Span::from(n_warnings), ])) @@ -136,7 +136,7 @@ impl TableList<12> for TasksTable { Cell::from(polls_width.update_str(task.total_polls().to_string())), Cell::from(kind_width.update_str(task.kind()).to_owned()), Cell::from(location_width.update_str(task.location()).to_owned()), - Cell::from(Spans::from( + Cell::from(Line::from( task.formatted_fields() .iter() .flatten() @@ -173,9 +173,9 @@ impl TableList<12> for TasksTable { .style(header_style); let table = if table_list_state.sort_descending { - Table::new(rows) + Table::default().rows(rows) } else { - Table::new(rows.rev()) + Table::default().rows(rows.rev()) }; let block = styles.border_block().title(vec![ @@ -201,7 +201,7 @@ impl TableList<12> for TasksTable { .tasks_state() .warnings() .map(|warning| { - ListItem::new(Text::from(Spans::from(vec![ + ListItem::new(Text::from(Line::from(vec![ styles.warning_wide(), // TODO(eliza): it would be nice to handle singular vs plural... Span::from(format!("{} {}", warning.count(), warning.summary())), @@ -275,7 +275,7 @@ impl TableList<12> for TasksTable { if let Some(area) = warnings_area { let block = styles .border_block() - .title(Spans::from(vec![bold("Warnings")])); + .title(Line::from(vec![bold("Warnings")])); frame.render_widget(widgets::List::new(warnings).block(block), area); }