Skip to content

Commit

Permalink
chore(deps): update ratatui to 0.26.0
Browse files Browse the repository at this point in the history
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)`.
  • Loading branch information
joshka committed Feb 17, 2024
1 parent 4150253 commit cc4570b
Show file tree
Hide file tree
Showing 14 changed files with 618 additions and 564 deletions.
1,025 changes: 541 additions & 484 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tokio-console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,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`.
Expand Down
6 changes: 3 additions & 3 deletions tokio-console/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(" "),
Expand Down
8 changes: 4 additions & 4 deletions tokio-console/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -157,7 +157,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();
Expand All @@ -174,13 +174,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, "),
Expand Down
12 changes: 6 additions & 6 deletions tokio-console/src/view/async_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
use ratatui::{
layout,
style::{self, Color, Style},
text::Spans,
text::Line,
widgets::{Cell, Row, Table},
};

Expand Down Expand Up @@ -56,10 +56,10 @@ impl TableList<9> for AsyncOpsTable {
Self::HEADER[8].len() + 1,
];

fn render<B: ratatui::backend::Backend>(
fn render(
table_list_state: &mut TableListState<Self, 9>,
styles: &view::Styles,
frame: &mut ratatui::terminal::Frame<B>,
frame: &mut ratatui::terminal::Frame,
area: layout::Rect,
state: &mut State,
ctx: Self::Context,
Expand Down Expand Up @@ -144,7 +144,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()
Expand Down Expand Up @@ -184,9 +184,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!(
Expand Down
24 changes: 12 additions & 12 deletions tokio-console/src/view/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::view::{self, bold};

use ratatui::{
layout,
text::{Span, Spans, Text},
text::{Line, Span, Text},
widgets::{Paragraph, Widget},
};

Expand Down Expand Up @@ -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;
}

Expand All @@ -66,19 +66,19 @@ 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.
// Otherwise, append only the separator - we accounted for its
// 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");
}
}
Expand Down Expand Up @@ -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)));

Expand Down Expand Up @@ -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)));
Expand All @@ -153,6 +153,6 @@ impl ControlDisplay {
}));
}

Spans::from(spans)
Line::from(spans)
}
}
4 changes: 2 additions & 2 deletions tokio-console/src/view/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ impl<'a> HelpView<'a> {
}
}

pub(crate) fn render<B: ratatui::backend::Backend>(
pub(crate) fn render(
&mut self,
styles: &view::Styles,
frame: &mut ratatui::terminal::Frame<B>,
frame: &mut ratatui::terminal::Frame,
_area: layout::Rect,
_state: &mut State,
) {
Expand Down
4 changes: 2 additions & 2 deletions tokio-console/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ impl View {
input::is_help_toggle(event) || (self.show_help_modal && input::is_esc(event))
}

pub(crate) fn render<B: ratatui::backend::Backend>(
pub(crate) fn render(
&mut self,
frame: &mut ratatui::terminal::Frame<B>,
frame: &mut ratatui::terminal::Frame,
area: layout::Rect,
state: &mut State,
) {
Expand Down
4 changes: 2 additions & 2 deletions tokio-console/src/view/percentiles.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use ratatui::{
text::{Spans, Text},
text::{Line, Text},
widgets::{Paragraph, Widget},
};

Expand Down Expand Up @@ -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),
Expand Down
20 changes: 10 additions & 10 deletions tokio-console/src/view/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -38,10 +38,10 @@ impl ResourceView {
self.async_ops_table.update_input(event)
}

pub(crate) fn render<B: ratatui::backend::Backend>(
pub(crate) fn render(
&mut self,
styles: &view::Styles,
frame: &mut ratatui::terminal::Frame<B>,
frame: &mut ratatui::terminal::Frame,
area: layout::Rect,
state: &mut State,
) {
Expand Down Expand Up @@ -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();
Expand All @@ -97,7 +97,7 @@ impl ResourceView {
.formatted_attributes()
.iter()
.cloned()
.map(Spans::from),
.map(Line::from),
);

let resource_widget =
Expand Down
12 changes: 6 additions & 6 deletions tokio-console/src/view/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
use ratatui::{
layout,
style::{self, Color, Style},
text::Spans,
text::Line,
widgets::{Cell, Row, Table},
};

Expand Down Expand Up @@ -50,10 +50,10 @@ impl TableList<9> for ResourcesTable {
Self::HEADER[8].len() + 1,
];

fn render<B: ratatui::backend::Backend>(
fn render(
table_list_state: &mut TableListState<Self, 9>,
styles: &view::Styles,
frame: &mut ratatui::terminal::Frame<B>,
frame: &mut ratatui::terminal::Frame,
area: layout::Rect,
state: &mut State,
_: Self::Context,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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!(
Expand Down
8 changes: 4 additions & 4 deletions tokio-console/src/view/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub(crate) trait TableList<const N: usize> {
const HEADER: &'static [&'static str; N];
const WIDTHS: &'static [usize; N];

fn render<B: ratatui::backend::Backend>(
fn render(
state: &mut TableListState<Self, N>,
styles: &view::Styles,
frame: &mut ratatui::terminal::Frame<B>,
frame: &mut ratatui::terminal::Frame,
area: layout::Rect,
state: &mut state::State,
cx: Self::Context,
Expand Down Expand Up @@ -168,10 +168,10 @@ impl<T: TableList<N>, const N: usize> TableListState<T, N> {
.unwrap_or_default()
}

pub(in crate::view) fn render<B: ratatui::backend::Backend>(
pub(in crate::view) fn render(
&mut self,
styles: &view::Styles,
frame: &mut ratatui::terminal::Frame<B>,
frame: &mut ratatui::terminal::Frame,
area: layout::Rect,
state: &mut state::State,
ctx: T::Context,
Expand Down
Loading

0 comments on commit cc4570b

Please sign in to comment.