diff options
author | cyqsimon <28627918+cyqsimon@users.noreply.github.com> | 2023-08-25 15:15:14 +0800 |
---|---|---|
committer | cyqsimon <28627918+cyqsimon@users.noreply.github.com> | 2023-08-25 15:15:14 +0800 |
commit | e06b5956a87fac022322c30572b2bb3dc8bbf938 (patch) | |
tree | 47bc0c0b0efc015a5fb0162f3c8c2a4f6f23f10b | |
parent | 94df6e07db856cfffcc2e1dcf13942acdb2fcbd9 (diff) |
Switch from `tui` to `ratatui`
-rw-r--r-- | Cargo.lock | 46 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/display/components/header_details.rs | 12 | ||||
-rw-r--r-- | src/display/components/help_text.rs | 12 | ||||
-rw-r--r-- | src/display/components/layout.rs | 16 | ||||
-rw-r--r-- | src/display/components/table.rs | 12 | ||||
-rw-r--r-- | src/display/raw_terminal_backend.rs | 6 | ||||
-rw-r--r-- | src/display/ui.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/tests/fakes/fake_output.rs | 6 |
10 files changed, 67 insertions, 53 deletions
@@ -123,13 +123,13 @@ dependencies = [ "pnet_base", "pnet_macros_support", "procfs", + "ratatui", "regex", "resolv-conf", "structopt", "sysinfo", "tokio", "trust-dns-resolver", - "tui", "unicode-width", "zip", ] @@ -388,9 +388,9 @@ dependencies = [ [[package]] name = "crossterm" -version = "0.25.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" +checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" dependencies = [ "bitflags 1.3.2", "crossterm_winapi", @@ -787,6 +787,12 @@ dependencies = [ ] [[package]] +name = "indoc" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c785eefb63ebd0e33416dfcb8d6da0bf27ce752843a45632a67bf10d4d4b5c4" + +[[package]] name = "inout" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1152,6 +1158,12 @@ dependencies = [ ] [[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] name = "pbkdf2" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1422,6 +1434,21 @@ dependencies = [ ] [[package]] +name = "ratatui" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8285baa38bdc9f879d92c0e37cb562ef38aa3aeefca22b3200186bc39242d3d5" +dependencies = [ + "bitflags 2.4.0", + "cassowary", + "crossterm 0.26.1", + "indoc", + "paste", + "unicode-segmentation", + "unicode-width", +] + +[[package]] name = "rayon" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1966,19 +1993,6 @@ dependencies = [ ] [[package]] -name = "tui" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1" -dependencies = [ - "bitflags 1.3.2", - "cassowary", - "crossterm 0.25.0", - "unicode-segmentation", - "unicode-width", -] - -[[package]] name = "typenum" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -21,7 +21,7 @@ exclude = ["src/tests/*", "demo.gif"] [dependencies] pnet = "0.34.0" ipnetwork = "0.20.0" -tui = { version = "0.19", default-features = false, features = ["crossterm"] } +ratatui = "0.22.0" crossterm = "0.27.0" structopt = "0.3" failure = "0.1.8" diff --git a/src/display/components/header_details.rs b/src/display/components/header_details.rs index c321265..768f64d 100644 --- a/src/display/components/header_details.rs +++ b/src/display/components/header_details.rs @@ -1,11 +1,11 @@ use crate::display::{DisplayBandwidth, UIState}; +use ::ratatui::backend::Backend; +use ::ratatui::layout::{Alignment, Rect}; +use ::ratatui::style::{Color, Modifier, Style}; +use ::ratatui::terminal::Frame; +use ::ratatui::text::Span; +use ::ratatui::widgets::Paragraph; use ::std::time::{Duration, Instant}; -use ::tui::backend::Backend; -use ::tui::layout::{Alignment, Rect}; -use ::tui::style::{Color, Modifier, Style}; -use ::tui::terminal::Frame; -use ::tui::text::Span; -use ::tui::widgets::Paragraph; const SECONDS_IN_DAY: u64 = 86400; diff --git a/src/display/components/help_text.rs b/src/display/components/help_text.rs index 29c8267..6fd0759 100644 --- a/src/display/components/help_text.rs +++ b/src/display/components/help_text.rs @@ -1,9 +1,9 @@ -use ::tui::backend::Backend; -use ::tui::layout::{Alignment, Rect}; -use ::tui::style::{Modifier, Style}; -use ::tui::terminal::Frame; -use ::tui::text::Span; -use ::tui::widgets::Paragraph; +use ::ratatui::backend::Backend; +use ::ratatui::layout::{Alignment, Rect}; +use ::ratatui::style::{Modifier, Style}; +use ::ratatui::terminal::Frame; +use ::ratatui::text::Span; +use ::ratatui::widgets::Paragraph; pub struct HelpText { pub paused: bool, diff --git a/src/display/components/layout.rs b/src/display/components/layout.rs index 51c0175..06cc0db 100644 --- a/src/display/components/layout.rs +++ b/src/display/components/layout.rs @@ -1,6 +1,6 @@ -use ::tui::backend::Backend; -use ::tui::layout::{Constraint, Direction, Rect}; -use ::tui::terminal::Frame; +use ::ratatui::backend::Backend; +use ::ratatui::layout::{Constraint, Direction, Rect}; +use ::ratatui::terminal::Frame; use super::HeaderDetails; use super::HelpText; @@ -10,7 +10,7 @@ const FIRST_HEIGHT_BREAKPOINT: u16 = 30; const FIRST_WIDTH_BREAKPOINT: u16 = 120; fn top_app_and_bottom_split(rect: Rect) -> (Rect, Rect, Rect) { - let parts = ::tui::layout::Layout::default() + let parts = ::ratatui::layout::Layout::default() .direction(Direction::Vertical) .margin(0) .constraints( @@ -37,12 +37,12 @@ impl<'a> Layout<'a> { .into_iter() .fold(vec![rect], |mut layout, direction| { let last_rect = layout.pop().unwrap(); - let mut halves = ::tui::layout::Layout::default() + let halves = ::ratatui::layout::Layout::default() .direction(direction) .margin(0) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) .split(last_rect); - layout.append(&mut halves); + layout.append(&mut halves.to_vec()); layout }) } @@ -74,12 +74,12 @@ impl<'a> Layout<'a> { self.progressive_split(rect, vec![Direction::Vertical]) } else { // default layout - let halves = ::tui::layout::Layout::default() + let halves = ::ratatui::layout::Layout::default() .direction(Direction::Vertical) .margin(0) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) .split(rect); - let top_quarters = ::tui::layout::Layout::default() + let top_quarters = ::ratatui::layout::Layout::default() .direction(Direction::Horizontal) .margin(0) .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) diff --git a/src/display/components/table.rs b/src/display/components/table.rs index d161451..ccfd9c5 100644 --- a/src/display/components/table.rs +++ b/src/display/components/table.rs @@ -2,11 +2,11 @@ use ::std::collections::{BTreeMap, HashMap}; use ::std::iter::FromIterator; use ::unicode_width::UnicodeWidthChar; -use ::tui::backend::Backend; -use ::tui::layout::{Constraint, Rect}; -use ::tui::style::{Color, Style}; -use ::tui::terminal::Frame; -use ::tui::widgets::{Block, Borders, Row}; +use ::ratatui::backend::Backend; +use ::ratatui::layout::{Constraint, Rect}; +use ::ratatui::style::{Color, Style}; +use ::ratatui::terminal::Frame; +use ::ratatui::widgets::{Block, Borders, Row}; use crate::display::{Bandwidth, DisplayBandwidth, UIState}; use crate::network::{display_connection_string, display_ip_or_host}; @@ -292,7 +292,7 @@ impl<'a> Table<'a> { let table_rows = rows.map(|row| Row::new(row).style(Style::default())); let width_constraints: Vec<Constraint> = widths.iter().map(|w| Constraint::Length(*w)).collect(); - let table = ::tui::widgets::Table::new(table_rows) + let table = ::ratatui::widgets::Table::new(table_rows) .block(Block::default().title(self.title).borders(Borders::ALL)) .header(Row::new(column_names).style(Style::default().fg(Color::Yellow))) .widths(&width_constraints) diff --git a/src/display/raw_terminal_backend.rs b/src/display/raw_terminal_backend.rs index 3ae299a..48b4b50 100644 --- a/src/display/raw_terminal_backend.rs +++ b/src/display/raw_terminal_backend.rs @@ -7,10 +7,10 @@ // that implements the Backend TUI trait, but does nothing // this way, we don't need to create the TermionBackend // and thus skew our stdout when we don't need it +use ::ratatui::backend::Backend; +use ::ratatui::buffer::Cell; +use ::ratatui::layout::Rect; use ::std::io; -use ::tui::backend::Backend; -use ::tui::buffer::Cell; -use ::tui::layout::Rect; pub struct RawTerminalBackend {} diff --git a/src/display/ui.rs b/src/display/ui.rs index 9a1bf80..bc459cc 100644 --- a/src/display/ui.rs +++ b/src/display/ui.rs @@ -1,7 +1,7 @@ use ::std::collections::HashMap; -use ::tui::backend::Backend; -use ::tui::Terminal; +use ::ratatui::backend::Backend; +use ::ratatui::Terminal; use crate::display::components::{HeaderDetails, HelpText, Layout, Table}; use crate::display::UIState; diff --git a/src/main.rs b/src/main.rs index 445e4fb..dfc8ce9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,13 +20,13 @@ use ::std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use ::std::sync::{Arc, Mutex}; use ::std::thread; use ::std::thread::park_timeout; -use ::tui::backend::Backend; +use ::ratatui::backend::Backend; use std::process; use ::std::net::Ipv4Addr; use ::std::time::{Duration, Instant}; -use ::tui::backend::CrosstermBackend; +use ::ratatui::backend::CrosstermBackend; use std::sync::RwLock; use structopt::StructOpt; diff --git a/src/tests/fakes/fake_output.rs b/src/tests/fakes/fake_output.rs index ef7ea3c..dd345e4 100644 --- a/src/tests/fakes/fake_output.rs +++ b/src/tests/fakes/fake_output.rs @@ -1,9 +1,9 @@ +use ::ratatui::backend::Backend; +use ::ratatui::buffer::Cell; +use ::ratatui::layout::Rect; use ::std::collections::HashMap; use ::std::io; use ::std::sync::{Arc, Mutex}; -use ::tui::backend::Backend; -use ::tui::buffer::Cell; -use ::tui::layout::Rect; #[derive(Hash, Debug, PartialEq)] pub enum TerminalEvent { |