Skip to content

Commit

Permalink
Merge pull request #274 from imsnif/ratatui
Browse files Browse the repository at this point in the history
Switch from `tui` to `ratatui`
  • Loading branch information
cyqsimon authored Aug 25, 2023
2 parents 94df6e0 + e06b595 commit b2a045a
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 53 deletions.
46 changes: 30 additions & 16 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions src/display/components/header_details.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
12 changes: 6 additions & 6 deletions src/display/components/help_text.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
16 changes: 8 additions & 8 deletions src/display/components/layout.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(
Expand All @@ -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
})
}
Expand Down Expand Up @@ -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())
Expand Down
12 changes: 6 additions & 6 deletions src/display/components/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/display/raw_terminal_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
4 changes: 2 additions & 2 deletions src/display/ui.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/tests/fakes/fake_output.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit b2a045a

Please sign in to comment.