Skip to content

Commit

Permalink
chore: migrate to ratatui and update crossterm
Browse files Browse the repository at this point in the history
  • Loading branch information
joshka committed May 24, 2023
1 parent 2617504 commit b7b0b81
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 137 deletions.
112 changes: 28 additions & 84 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tokio-console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ clap = { version = "3", features = ["cargo", "derive", "env"] }
tokio = { version = "1", features = ["full", "rt-multi-thread"] }
tonic = { version = "0.9", features = ["transport"] }
futures = "0.3"
tui = { version = "0.16.0", default-features = false, features = ["crossterm"] }
ratatui = { version = "0.20.1", default-features = false, features = ["crossterm"] }
tower = "0.4.12"
tracing = "0.1"
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
tracing-journald = { version = "0.2", optional = true }
prost-types = "0.11"
crossterm = { version = "0.20", features = ["event-stream"] }
crossterm = { version = "0.26.1", features = ["event-stream"] }
color-eyre = { version = "0.6", features = ["issue-url"] }
hdrhistogram = { version = "7.3.0", default-features = false, features = ["serialization"] }
h2 = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions tokio-console/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ impl Connection {
}
}

pub fn render(&self, styles: &crate::view::Styles) -> tui::text::Spans {
use tui::{
pub fn render(&self, styles: &crate::view::Styles) -> ratatui::text::Spans {
use ratatui::{
style::{Color, Modifier},
text::{Span, Spans},
};
Expand Down
4 changes: 3 additions & 1 deletion tokio-console/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// TODO(eliza): support TUI backends other than crossterm?
// TODO(eliza): support Ratatui backends other than crossterm?
// This would probably involve using `spawn_blocking` to drive their blocking
// input-handling mechanisms in the background...
pub use crossterm::event::*;
Expand All @@ -13,10 +13,12 @@ pub fn should_quit(input: &Event) -> bool {
Key(KeyEvent {
code: Char('c'),
modifiers,
..
})
| Key(KeyEvent {
code: Char('d'),
modifiers,
..
}) if modifiers.contains(KeyModifiers::CONTROL) => true,
_ => false,
}
Expand Down
2 changes: 1 addition & 1 deletion tokio-console/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use state::State;

use futures::stream::StreamExt;
use tokio::sync::{mpsc, watch};
use tui::{
use ratatui::{
layout::{Constraint, Direction, Layout},
style::Color,
text::{Span, Spans},
Expand Down
2 changes: 1 addition & 1 deletion tokio-console/src/state/async_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{
rc::{Rc, Weak},
time::{Duration, SystemTime},
};
use tui::text::Span;
use ratatui::text::Span;

#[derive(Default, Debug)]
pub(crate) struct AsyncOpsState {
Expand Down
2 changes: 1 addition & 1 deletion tokio-console/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
time::{Duration, SystemTime},
};
use tasks::{Details, Task, TasksState};
use tui::{
use ratatui::{
style::{Color, Modifier},
text::Span,
};
Expand Down
2 changes: 1 addition & 1 deletion tokio-console/src/state/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
rc::Rc,
time::{Duration, SystemTime},
};
use tui::{style::Color, text::Span};
use ratatui::{style::Color, text::Span};

#[derive(Default, Debug)]
pub(crate) struct ResourcesState {
Expand Down
2 changes: 1 addition & 1 deletion tokio-console/src/state/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{
rc::{Rc, Weak},
time::{Duration, SystemTime},
};
use tui::{style::Color, text::Span};
use ratatui::{style::Color, text::Span};

#[derive(Default, Debug)]
pub(crate) struct TasksState {
Expand Down
2 changes: 1 addition & 1 deletion tokio-console/src/term.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use color_eyre::eyre::WrapErr;
use std::io;
pub use tui::{backend::CrosstermBackend, Terminal};
pub use ratatui::{backend::CrosstermBackend, Terminal};

pub fn init_crossterm() -> color_eyre::Result<(Terminal<CrosstermBackend<io::Stdout>>, OnShutdown)>
{
Expand Down
6 changes: 3 additions & 3 deletions tokio-console/src/view/async_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
},
};

use tui::{
use ratatui::{
layout,
style::{self, Color, Style},
text::Spans,
Expand Down Expand Up @@ -55,10 +55,10 @@ impl TableList<9> for AsyncOpsTable {
Self::HEADER[8].len() + 1,
];

fn render<B: tui::backend::Backend>(
fn render<B: ratatui::backend::Backend>(
table_list_state: &mut TableListState<Self, 9>,
styles: &view::Styles,
frame: &mut tui::terminal::Frame<B>,
frame: &mut ratatui::terminal::Frame<B>,
area: layout::Rect,
state: &mut State,
ctx: Self::Context,
Expand Down
6 changes: 3 additions & 3 deletions tokio-console/src/view/durations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::cmp;

use tui::{
use ratatui::{
layout::{self},
widgets::Widget,
};
Expand All @@ -15,7 +15,7 @@ use crate::{
// This also gives at characters for the sparkline itself.
const MIN_HISTOGRAM_BLOCK_WIDTH: u16 = 22;

/// This is a tui-rs widget to visualize durations as a list of percentiles
/// This is a Ratatui widget to visualize durations as a list of percentiles
/// and if possible, a mini-histogram too.
///
/// This widget wraps the [`Percentiles`] and [`MiniHistogram`] widgets which
Expand All @@ -41,7 +41,7 @@ pub(crate) struct Durations<'a> {
}

impl<'a> Widget for Durations<'a> {
fn render(self, area: tui::layout::Rect, buf: &mut tui::buffer::Buffer) {
fn render(self, area: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) {
// Only split the durations area in half if we're also drawing a
// sparkline. We require UTF-8 to draw the sparkline and also enough width.
let (percentiles_area, histogram_area) = if self.styles.utf8 {
Expand Down
Loading

0 comments on commit b7b0b81

Please sign in to comment.