Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump ratatui to 0.24.0 #327

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 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 @@ -34,7 +34,7 @@ log = "0.4.20"
once_cell = "1.18.0"
pnet = "0.34.0"
pnet_macros_support = "0.34.0"
ratatui = "0.23.0"
ratatui = "0.24.0"
resolv-conf = "0.7.0"
simplelog = "0.12.1"
thiserror = "1.0.50"
Expand Down
19 changes: 3 additions & 16 deletions src/display/components/header_details.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::time::{Duration, Instant};

use ratatui::{
backend::Backend,
layout::{Alignment, Rect},
style::{Color, Modifier, Style},
terminal::Frame,
Expand Down Expand Up @@ -42,7 +41,7 @@ pub struct HeaderDetails<'a> {
}

impl<'a> HeaderDetails<'a> {
pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect) {
pub fn render(&self, frame: &mut Frame, rect: Rect) {
let bandwidth = self.bandwidth_string();
let color = if self.paused {
Color::Yellow
Expand All @@ -63,13 +62,7 @@ impl<'a> HeaderDetails<'a> {
self.render_bandwidth(frame, rect, &bandwidth, color);
}

fn render_bandwidth(
&self,
frame: &mut Frame<impl Backend>,
rect: Rect,
bandwidth: &str,
color: Color,
) {
fn render_bandwidth(&self, frame: &mut Frame, rect: Rect, bandwidth: &str, color: Color) {
let bandwidth_text = Span::styled(
bandwidth,
Style::default().fg(color).add_modifier(Modifier::BOLD),
Expand All @@ -95,13 +88,7 @@ impl<'a> HeaderDetails<'a> {
format!(" Total {t} (Up / Down): {up} / {down}{paused}")
}

fn render_elapsed_time(
&self,
frame: &mut Frame<impl Backend>,
rect: Rect,
elapsed_time: &str,
color: Color,
) {
fn render_elapsed_time(&self, frame: &mut Frame, rect: Rect, elapsed_time: &str, color: Color) {
let elapsed_time_text = Span::styled(
elapsed_time,
Style::default().fg(color).add_modifier(Modifier::BOLD),
Expand Down
3 changes: 1 addition & 2 deletions src/display/components/help_text.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ratatui::{
backend::Backend,
layout::{Alignment, Rect},
style::{Modifier, Style},
terminal::Frame,
Expand All @@ -22,7 +21,7 @@ const TEXT_WHEN_DNS_SHOWN: &str = " (DNS queries shown).";
const TEXT_TAB_TIP: &str = " Use <TAB> to rearrange tables.";

impl HelpText {
pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect) {
pub fn render(&self, frame: &mut Frame, rect: Rect) {
let pause_content = if self.paused {
TEXT_WHEN_PAUSED
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/display/components/layout.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ratatui::{
backend::Backend,
layout::{Constraint, Direction, Rect},
terminal::Frame,
};
Expand Down Expand Up @@ -100,7 +99,7 @@ impl<'a> Layout<'a> {
}
}

pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect, ui_offset: usize) {
pub fn render(&self, frame: &mut Frame, rect: Rect, ui_offset: usize) {
let (top, app, bottom) = top_app_and_bottom_split(rect);
let layout_slots = self.build_layout(app);
for i in 0..layout_slots.len() {
Expand Down
3 changes: 1 addition & 2 deletions src/display/components/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{collections::HashMap, fmt, iter::FromIterator, net::IpAddr, ops::Index
use derivative::Derivative;
use itertools::Itertools;
use ratatui::{
backend::Backend,
layout::{Constraint, Rect},
style::{Color, Style},
terminal::Frame,
Expand Down Expand Up @@ -326,7 +325,7 @@ impl Table {
}

/// See [`Table`] for layout rules.
pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect) {
pub fn render(&self, frame: &mut Frame, rect: Rect) {
let (computed_layout, spacer_width) = {
// pick the largest possible layout, constrained by the available width
let &(_, layout) = self
Expand Down
13 changes: 12 additions & 1 deletion src/display/raw_terminal_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

use std::io;

use ratatui::{backend::Backend, buffer::Cell, layout::Rect};
use ratatui::{
backend::{Backend, WindowSize},
buffer::Cell,
layout::{Rect, Size},
};

pub struct RawTerminalBackend {}

Expand Down Expand Up @@ -46,6 +50,13 @@ impl Backend for RawTerminalBackend {
Ok(Rect::new(0, 0, 0, 0))
}

fn window_size(&mut self) -> io::Result<WindowSize> {
Ok(WindowSize {
columns_rows: Size::default(),
pixels: Size::default(),
})
}

fn flush(&mut self) -> io::Result<()> {
Ok(())
}
Expand Down
16 changes: 15 additions & 1 deletion src/tests/fakes/fake_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use std::{
sync::{Arc, Mutex},
};

use ratatui::{backend::Backend, buffer::Cell, layout::Rect};
use ratatui::{
backend::{Backend, WindowSize},
buffer::Cell,
layout::{Rect, Size},
};

#[derive(Hash, Debug, PartialEq)]
pub enum TerminalEvent {
Expand Down Expand Up @@ -109,6 +113,16 @@ impl Backend for TestBackend {
Ok(Rect::new(0, 0, *terminal_width, *terminal_height))
}

fn window_size(&mut self) -> io::Result<WindowSize> {
let width = *self.terminal_width.lock().unwrap();
let height = *self.terminal_height.lock().unwrap();

Ok(WindowSize {
columns_rows: Size { width, height },
pixels: Size::default(),
})
}

fn flush(&mut self) -> io::Result<()> {
self.events.lock().unwrap().push(TerminalEvent::Flush);
Ok(())
Expand Down