Skip to content

Commit

Permalink
deps: update ratatui version (#1362)
Browse files Browse the repository at this point in the history
* cargo update ratatui

* replace convert_arc_labels with convert_mem_labels

* remove redundant generic

---------

Co-authored-by: Clement Tsang <[email protected]>
  • Loading branch information
jamartin9 and ClementTsang authored Dec 25, 2023
1 parent c10779e commit 28d2950
Show file tree
Hide file tree
Showing 21 changed files with 314 additions and 356 deletions.
429 changes: 214 additions & 215 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ sysinfo = "=0.29.11"
thiserror = "1.0.50"
time = { version = "0.3.30", features = ["formatting", "macros"] }
toml_edit = { version = "0.21.0", features = ["serde"] }
tui = { version = "0.22.0", package = "ratatui" }
tui = { version = "0.25.0", package = "ratatui" }
unicode-segmentation = "1.10.1"
unicode-width = "0.1.11"

Expand Down
3 changes: 2 additions & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ fn main() -> Result<()> {

#[cfg(feature = "zfs")]
{
let arc_labels = convert_arc_labels(&app.data_collection);
let arc_labels =
convert_mem_label(&app.data_collection.arc_harvest);
app.converted_data.arc_labels = arc_labels;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl Painter {
self.styled_help_text = styled_help_spans.into_iter().map(Line::from).collect();
}

fn draw_frozen_indicator<B: Backend>(&self, f: &mut Frame<'_, B>, draw_loc: Rect) {
fn draw_frozen_indicator(&self, f: &mut Frame<'_>, draw_loc: Rect) {
f.render_widget(
Paragraph::new(Span::styled(
"Frozen, press 'f' to unfreeze",
Expand Down Expand Up @@ -767,8 +767,8 @@ impl Painter {
Ok(())
}

fn draw_widgets_with_constraints<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, widgets: &BottomColRow,
fn draw_widgets_with_constraints(
&self, f: &mut Frame<'_>, app_state: &mut App, widgets: &BottomColRow,
widget_draw_locs: &[Rect],
) {
use BottomWidgetType::*;
Expand Down
9 changes: 4 additions & 5 deletions src/canvas/dialogs/dd_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::cmp::min;

use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
terminal::Frame,
text::{Line, Span, Text},
Expand Down Expand Up @@ -206,8 +205,8 @@ impl Painter {
None
}

fn draw_dd_confirm_buttons<B: Backend>(
&self, f: &mut Frame<'_, B>, button_draw_loc: &Rect, app_state: &mut App,
fn draw_dd_confirm_buttons(
&self, f: &mut Frame<'_>, button_draw_loc: &Rect, app_state: &mut App,
) {
if MAX_PROCESS_SIGNAL == 1 || !app_state.app_config_fields.is_advanced_kill {
let (yes_button, no_button) = match app_state.delete_dialog_state.selected_signal {
Expand Down Expand Up @@ -351,8 +350,8 @@ impl Painter {
}
}

pub fn draw_dd_dialog<B: Backend>(
&self, f: &mut Frame<'_, B>, dd_text: Option<Text<'_>>, app_state: &mut App, draw_loc: Rect,
pub fn draw_dd_dialog(
&self, f: &mut Frame<'_>, dd_text: Option<Text<'_>>, app_state: &mut App, draw_loc: Rect,
) -> bool {
if let Some(dd_text) = dd_text {
let dd_title = if app_state.dd_err.is_some() {
Expand Down
5 changes: 1 addition & 4 deletions src/canvas/dialogs/help_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::cmp::{max, min};

use tui::{
backend::Backend,
layout::{Alignment, Rect},
terminal::Frame,
text::Line,
Expand All @@ -16,9 +15,7 @@ const HELP_BASE: &str = " Help ── Esc to close ";

// TODO: [REFACTOR] Make generic dialog boxes to build off of instead?
impl Painter {
pub fn draw_help_dialog<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect,
) {
pub fn draw_help_dialog(&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect) {
let help_title = Line::from(vec![
Span::styled(" Help ", self.colours.widget_title_style),
Span::styled(
Expand Down
5 changes: 2 additions & 3 deletions src/canvas/widgets/basic_table_arrows.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
terminal::Frame,
text::Line,
Expand All @@ -13,8 +12,8 @@ use crate::{
};

impl Painter {
pub fn draw_basic_table_arrows<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
pub fn draw_basic_table_arrows(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
if let Some(current_table) = app_state.widget_map.get(&widget_id) {
let current_table = if let BottomWidgetType::ProcSort = current_table.widget_type {
Expand Down
20 changes: 10 additions & 10 deletions src/canvas/widgets/battery_display.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
terminal::Frame,
text::{Line, Span},
Expand All @@ -16,8 +15,8 @@ use crate::{
};

impl Painter {
pub fn draw_battery_display<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, draw_border: bool,
pub fn draw_battery_display(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, draw_border: bool,
widget_id: u64,
) {
let should_get_widget_bounds = app_state.should_get_widget_bounds();
Expand Down Expand Up @@ -249,19 +248,20 @@ impl Painter {

// Draw bar
f.render_widget(
Table::new(battery_charge_rows)
Table::new(battery_charge_rows, [Constraint::Percentage(100)])
.block(battery_block.clone())
.header(header.clone())
.widths(&[Constraint::Percentage(100)]),
.header(header.clone()),
margined_draw_loc,
);

// Draw info
f.render_widget(
Table::new(battery_rows)
.block(battery_block)
.header(header)
.widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]),
Table::new(
battery_rows,
[Constraint::Percentage(50), Constraint::Percentage(50)],
)
.block(battery_block)
.header(header),
margined_draw_loc,
);
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/canvas/widgets/cpu_basic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::cmp::min;

use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
terminal::Frame,
widgets::Block,
Expand All @@ -17,8 +16,8 @@ use crate::{

impl Painter {
/// Inspired by htop.
pub fn draw_basic_cpu<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
pub fn draw_basic_cpu(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
// Skip the first element, it's the "all" element
if app_state.converted_data.cpu_data.len() > 1 {
Expand Down
13 changes: 5 additions & 8 deletions src/canvas/widgets/cpu_graph.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::Cow;

use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
symbols::Marker,
terminal::Frame,
Expand All @@ -22,9 +21,7 @@ const AVG_POSITION: usize = 1;
const ALL_POSITION: usize = 0;

impl Painter {
pub fn draw_cpu<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
pub fn draw_cpu(&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64) {
let legend_width = (draw_loc.width as f64 * 0.15) as u16;

if legend_width < 6 {
Expand Down Expand Up @@ -175,8 +172,8 @@ impl Painter {
}
}

fn draw_cpu_graph<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
fn draw_cpu_graph(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
const Y_BOUNDS: [f64; 2] = [0.0, 100.5];
const Y_LABELS: [Cow<'static, str>; 2] = [Cow::Borrowed(" 0%"), Cow::Borrowed("100%")];
Expand Down Expand Up @@ -240,8 +237,8 @@ impl Painter {
}
}

fn draw_cpu_legend<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
fn draw_cpu_legend(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
let recalculate_column_widths = app_state.should_get_widget_bounds();
if let Some(cpu_widget_state) = app_state
Expand Down
6 changes: 3 additions & 3 deletions src/canvas/widgets/disk_table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use tui::{backend::Backend, layout::Rect, terminal::Frame};
use tui::{layout::Rect, terminal::Frame};

use crate::{
app::{self},
Expand All @@ -7,8 +7,8 @@ use crate::{
};

impl Painter {
pub fn draw_disk_table<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut app::App, draw_loc: Rect, widget_id: u64,
pub fn draw_disk_table(
&self, f: &mut Frame<'_>, app_state: &mut app::App, draw_loc: Rect, widget_id: u64,
) {
let recalculate_column_widths = app_state.should_get_widget_bounds();
if let Some(disk_widget_state) = app_state
Expand Down
5 changes: 2 additions & 3 deletions src/canvas/widgets/mem_basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
terminal::Frame,
widgets::Block,
Expand All @@ -10,8 +9,8 @@ use crate::{
};

impl Painter {
pub fn draw_basic_memory<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
pub fn draw_basic_memory(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
let mem_data = &app_state.converted_data.mem_data;
let mut draw_widgets: Vec<PipeGauge<'_>> = Vec::new();
Expand Down
5 changes: 2 additions & 3 deletions src/canvas/widgets/mem_graph.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::Cow;

use tui::{
backend::Backend,
layout::{Constraint, Rect},
symbols::Marker,
terminal::Frame,
Expand All @@ -14,8 +13,8 @@ use crate::{
};

impl Painter {
pub fn draw_memory_graph<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
pub fn draw_memory_graph(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
const Y_BOUNDS: [f64; 2] = [0.0, 100.5];
const Y_LABELS: [Cow<'static, str>; 2] = [Cow::Borrowed(" 0%"), Cow::Borrowed("100%")];
Expand Down
5 changes: 2 additions & 3 deletions src/canvas/widgets/network_basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
terminal::Frame,
text::{Line, Span},
Expand All @@ -9,8 +8,8 @@ use tui::{
use crate::{app::App, canvas::Painter, constants::*};

impl Painter {
pub fn draw_basic_network<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
pub fn draw_basic_network(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
let divided_loc = Layout::default()
.direction(Direction::Horizontal)
Expand Down
45 changes: 22 additions & 23 deletions src/canvas/widgets/network_graph.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
symbols::Marker,
terminal::Frame,
Expand All @@ -18,8 +17,8 @@ use crate::{
};

impl Painter {
pub fn draw_network<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
pub fn draw_network(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
if app_state.app_config_fields.use_old_network_legend {
const LEGEND_HEIGHT: u16 = 4;
Expand Down Expand Up @@ -50,8 +49,8 @@ impl Painter {
}
}

pub fn draw_network_graph<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
pub fn draw_network_graph(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
hide_legend: bool,
) {
if let Some(network_widget_state) =
Expand Down Expand Up @@ -167,8 +166,8 @@ impl Painter {
}
}

fn draw_network_labels<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
fn draw_network_labels(
&self, f: &mut Frame<'_>, app_state: &mut App, draw_loc: Rect, widget_id: u64,
) {
const NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "Total RX", "Total TX"];

Expand All @@ -187,22 +186,22 @@ impl Painter {

// Draw
f.render_widget(
Table::new(total_network)
.header(Row::new(NETWORK_HEADERS).style(self.colours.table_header_style))
.block(Block::default().borders(Borders::ALL).border_style(
if app_state.current_widget.widget_id == widget_id {
self.colours.highlighted_border_style
} else {
self.colours.border_style
},
))
.style(self.colours.text_style)
.widths(
&((std::iter::repeat(draw_loc.width.saturating_sub(2) / 4))
.take(4)
.map(Constraint::Length)
.collect::<Vec<_>>()),
),
Table::new(
total_network,
&((std::iter::repeat(draw_loc.width.saturating_sub(2) / 4))
.take(4)
.map(Constraint::Length)
.collect::<Vec<_>>()),
)
.header(Row::new(NETWORK_HEADERS).style(self.colours.table_header_style))
.block(Block::default().borders(Borders::ALL).border_style(
if app_state.current_widget.widget_id == widget_id {
self.colours.highlighted_border_style
} else {
self.colours.border_style
},
))
.style(self.colours.text_style),
draw_loc,
);
}
Expand Down
Loading

0 comments on commit 28d2950

Please sign in to comment.