diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2021-02-19 17:57:39 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-19 17:57:39 -0500 |
commit | cb1191ff355c79f9e8c3ee47234e8ef6da14e504 (patch) | |
tree | 87b186037ed9db165dac8d65f02c53a7844e6276 /src | |
parent | f2975c3a7cfdf5d5b287313b78c5cbb7367a04e1 (diff) |
deps: Update various deps as per 2021-02-19 (#420)
Major update is tui-rs from 0.13 to 0.14. This change allows us to update our tables to make them look nicer!
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 3 | ||||
-rw-r--r-- | src/canvas/widgets/battery_display.rs | 40 | ||||
-rw-r--r-- | src/canvas/widgets/cpu_graph.rs | 92 | ||||
-rw-r--r-- | src/canvas/widgets/disk_table.rs | 20 | ||||
-rw-r--r-- | src/canvas/widgets/network_graph.rs | 28 | ||||
-rw-r--r-- | src/canvas/widgets/process_table.rs | 43 | ||||
-rw-r--r-- | src/canvas/widgets/temp_table.rs | 26 | ||||
-rw-r--r-- | src/lib.rs | 4 |
8 files changed, 136 insertions, 120 deletions
@@ -2757,7 +2757,7 @@ impl App { /// Moves the mouse to the widget that was clicked on, then propagates the click down to be /// handled by the widget specifically. - pub fn left_mouse_click_movement(&mut self, x: u16, y: u16) { + pub fn on_left_mouse_up(&mut self, x: u16, y: u16) { // Pretty dead simple - iterate through the widget map and go to the widget where the click // is within. @@ -2769,6 +2769,7 @@ impl App { // Short circuit if we're in basic table... we might have to handle the basic table arrow // case here... + if let Some(bt) = &mut self.basic_table_widget_state { if let ( Some((left_tlc_x, left_tlc_y)), diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs index 8672ea1f..89b55bfd 100644 --- a/src/canvas/widgets/battery_display.rs +++ b/src/canvas/widgets/battery_display.rs @@ -129,40 +129,36 @@ impl BatteryDisplayWidget for Painter { charge_percentage, ); - let battery_items = vec![ - ["Charge %", &bars], - ["Consumption", &battery_details.watt_consumption], + let battery_items: Vec<Vec<&str>> = vec![ + vec!["Charge %", &bars], + vec!["Consumption", &battery_details.watt_consumption], if let Some(duration_until_full) = &battery_details.duration_until_full { - ["Time to full", duration_until_full] + vec!["Time to full", duration_until_full] } else if let Some(duration_until_empty) = &battery_details.duration_until_empty { - ["Time to empty", duration_until_empty] + vec!["Time to empty", duration_until_empty] } else { - ["Time to full/empty", "N/A"] + vec!["Time to full/empty", "N/A"] }, - ["Health %", &battery_details.health], + vec!["Health %", &battery_details.health], ]; - let battery_rows = battery_items.iter().map(|item| { - Row::StyledData( - item.iter(), - if charge_percentage < 10.0 { - self.colours.low_battery_colour - } else if charge_percentage < 50.0 { - self.colours.medium_battery_colour - } else { - self.colours.high_battery_colour - }, - ) + let battery_rows = battery_items.into_iter().map(|item| { + Row::new(item).style(if charge_percentage < 10.0 { + self.colours.low_battery_colour + } else if charge_percentage < 50.0 { + self.colours.medium_battery_colour + } else { + self.colours.high_battery_colour + }) }); // Draw f.render_widget( - Table::new([""].iter(), battery_rows) + Table::new(battery_rows) .block(battery_block) - .header_style(self.colours.table_header_style) - .widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]) - .header_gap(table_gap), + .header(Row::new(vec![""]).bottom_margin(table_gap)) + .widths(&[Constraint::Percentage(50), Constraint::Percentage(50)]), margined_draw_loc, ); } else { diff --git a/src/canvas/widgets/cpu_graph.rs b/src/canvas/widgets/cpu_graph.rs index 299fe032..e19da20a 100644 --- a/src/canvas/widgets/cpu_graph.rs +++ b/src/canvas/widgets/cpu_graph.rs @@ -1,5 +1,4 @@ use once_cell::sync::Lazy; -use std::borrow::Cow; use unicode_segmentation::UnicodeSegmentation; use crate::{ @@ -18,7 +17,7 @@ use tui::{ symbols::Marker, terminal::Frame, text::Span, - text::Spans, + text::{Spans, Text}, widgets::{Axis, Block, Borders, Chart, Dataset, Row, Table}, }; @@ -314,7 +313,7 @@ impl CpuGraphWidget for Painter { let sliced_cpu_data = &cpu_data[start_position..]; - let mut offset_scroll_index = cpu_widget_state + let offset_scroll_index = cpu_widget_state .scroll_state .current_scroll_position .saturating_sub(start_position); @@ -343,58 +342,59 @@ impl CpuGraphWidget for Painter { let dcw = &cpu_widget_state.table_width_state.desired_column_widths; let ccw = &cpu_widget_state.table_width_state.calculated_column_widths; - let cpu_rows = sliced_cpu_data.iter().enumerate().filter_map(|(itx, cpu)| { - let truncated_name: Cow<'_, str> = + let cpu_rows = sliced_cpu_data.iter().enumerate().map(|(itx, cpu)| { + let mut truncated_name = if let (Some(desired_column_width), Some(calculated_column_width)) = (dcw.get(0), ccw.get(0)) { if *desired_column_width > *calculated_column_width { - Cow::Borrowed(&cpu.short_cpu_name) + Text::raw(&cpu.short_cpu_name) } else { - Cow::Borrowed(&cpu.cpu_name) + Text::raw(&cpu.cpu_name) } } else { - Cow::Borrowed(&cpu.cpu_name) - }; - let truncated_legend: Cow<'_, str> = - if let Some(calculated_column_width) = ccw.get(0) { - if *calculated_column_width == 0 && cpu.legend_value.is_empty() { - Cow::Borrowed("All") - } else { - Cow::Borrowed(&cpu.legend_value) - } - } else { - Cow::Borrowed(&cpu.legend_value) + Text::raw(&cpu.cpu_name) }; - let cpu_string_row: Vec<Cow<'_, str>> = vec![truncated_name, truncated_legend]; + let is_first_column_hidden = if let Some(calculated_column_width) = ccw.get(0) { + *calculated_column_width == 0 + } else { + false + }; - if cpu_string_row.is_empty() { - offset_scroll_index += 1; - None + let truncated_legend = if is_first_column_hidden && cpu.legend_value.is_empty() { + // For the case where we only have room for one column, display "All" in the normally blank area. + Text::raw("All") } else { - Some(Row::StyledData( - cpu_string_row.into_iter(), - if itx == offset_scroll_index { - self.colours.currently_selected_text_style - } else if itx + start_position == ALL_POSITION { - self.colours.all_colour_style - } else if show_avg_cpu { - if itx + start_position == AVG_POSITION { - self.colours.avg_colour_style - } else { - self.colours.cpu_colour_styles[(itx + start_position - - AVG_POSITION - - 1) - % self.colours.cpu_colour_styles.len()] - } + Text::raw(&cpu.legend_value) + }; + + if !is_first_column_hidden + && itx == offset_scroll_index + && itx + start_position == ALL_POSITION + { + truncated_name.patch_style(self.colours.currently_selected_text_style); + Row::new(vec![truncated_name, truncated_legend]) + } else { + let cpu_string_row = vec![truncated_name, truncated_legend]; + + Row::new(cpu_string_row).style(if itx == offset_scroll_index { + self.colours.currently_selected_text_style + } else if itx + start_position == ALL_POSITION { + self.colours.all_colour_style + } else if show_avg_cpu { + if itx + start_position == AVG_POSITION { + self.colours.avg_colour_style } else { self.colours.cpu_colour_styles[(itx + start_position - - ALL_POSITION + - AVG_POSITION - 1) % self.colours.cpu_colour_styles.len()] - }, - )) + } + } else { + self.colours.cpu_colour_styles[(itx + start_position - ALL_POSITION - 1) + % self.colours.cpu_colour_styles.len()] + }) } }); @@ -407,14 +407,17 @@ impl CpuGraphWidget for Painter { // Draw f.render_stateful_widget( - Table::new(CPU_LEGEND_HEADER.iter(), cpu_rows) + Table::new(cpu_rows) .block( Block::default() .borders(Borders::ALL) .border_style(border_and_title_style), ) - .header_style(self.colours.table_header_style) - .highlight_style(self.colours.currently_selected_text_style) + .header( + Row::new(CPU_LEGEND_HEADER.to_vec()) + .style(self.colours.table_header_style) + .bottom_margin(table_gap), + ) .widths( &(cpu_widget_state .table_width_state @@ -422,8 +425,7 @@ impl CpuGraphWidget for Painter { .iter() .map(|calculated_width| Constraint::Length(*calculated_width as u16)) .collect::<Vec<_>>()), - ) - .header_gap(table_gap), + ), draw_loc, cpu_table_state, ); diff --git a/src/canvas/widgets/disk_table.rs b/src/canvas/widgets/disk_table.rs index 14cb4f60..7d493f17 100644 --- a/src/canvas/widgets/disk_table.rs +++ b/src/canvas/widgets/disk_table.rs @@ -4,7 +4,7 @@ use tui::{ layout::{Constraint, Direction, Layout, Rect}, terminal::Frame, text::Span, - text::Spans, + text::{Spans, Text}, widgets::{Block, Borders, Row, Table}, }; @@ -16,7 +16,6 @@ use crate::{ }, constants::*, }; -use std::borrow::Cow; use unicode_segmentation::UnicodeSegmentation; const DISK_HEADERS: [&str; 7] = ["Disk", "Mount", "Used", "Free", "Total", "R/s", "W/s"]; @@ -140,17 +139,17 @@ impl DiskTableWidget for Painter { let first_n = graphemes [..(*calculated_col_width as usize - 1)] .concat(); - return Cow::Owned(format!("{}…", first_n)); + return Text::raw(format!("{}…", first_n)); } } } } - Cow::Borrowed(entry) + Text::raw(entry) }, ); - Row::Data(truncated_data) + Row::new(truncated_data) }); let (border_style, highlight_style) = if is_on_widget { @@ -241,9 +240,13 @@ impl DiskTableWidget for Painter { // Draw! f.render_stateful_widget( - Table::new(DISK_HEADERS.iter(), disk_rows) + Table::new(disk_rows) .block(disk_block) - .header_style(self.colours.table_header_style) + .header( + Row::new(DISK_HEADERS.to_vec()) + .style(self.colours.table_header_style) + .bottom_margin(table_gap), + ) .highlight_style(highlight_style) .style(self.colours.text_style) .widths( @@ -253,8 +256,7 @@ impl DiskTableWidget for Painter { .iter() .map(|calculated_width| Constraint::Length(*calculated_width as u16)) .collect::<Vec<_>>()), - ) - .header_gap(table_gap), + ), margined_draw_loc, disk_table_state, ); diff --git a/src/canvas/widgets/network_graph.rs b/src/canvas/widgets/network_graph.rs index ce9d1ce7..b6ee080b 100644 --- a/src/canvas/widgets/network_graph.rs +++ b/src/canvas/widgets/network_graph.rs @@ -15,7 +15,7 @@ use tui::{ symbols::Marker, terminal::Frame, text::Span, - text::Spans, + text::{Spans, Text}, widgets::{Axis, Block, Borders, Chart, Dataset, Row, Table}, }; @@ -355,6 +355,12 @@ impl NetworkGraphWidget for Painter { fn draw_network_labels<B: Backend>( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { + let table_gap = if draw_loc.height < TABLE_GAP_HEIGHT_LIMIT { + 0 + } else { + app_state.app_config_fields.table_gap + }; + let rx_display = &app_state.canvas_data.rx_display; let tx_display = &app_state.canvas_data.tx_display; let total_rx_display = &app_state.canvas_data.total_rx_display; @@ -362,14 +368,14 @@ impl NetworkGraphWidget for Painter { // Gross but I need it to work... let total_network = vec![vec![ - rx_display, - tx_display, - total_rx_display, - total_tx_display, + Text::raw(rx_display), + Text::raw(tx_display), + Text::raw(total_rx_display), + Text::raw(total_tx_display), ]]; let mapped_network = total_network - .iter() - .map(|val| Row::StyledData(val.iter(), self.colours.text_style)); + .into_iter() + .map(|val| Row::new(val).style(self.colours.text_style)); // Calculate widths let intrinsic_widths = get_column_widths( @@ -389,7 +395,12 @@ impl NetworkGraphWidget for Painter { // Draw f.render_widget( - Table::new(NETWORK_HEADERS.iter(), mapped_network) + Table::new(mapped_network) + .header( + Row::new(NETWORK_HEADERS.to_vec()) + .style(self.colours.table_header_style) + .bottom_margin(table_gap), + ) .block(Block::default().borders(Borders::ALL).border_style( if app_state.current_widget.widget_id == widget_id { self.colours.highlighted_border_style @@ -397,7 +408,6 @@ impl NetworkGraphWidget for Painter { self.colours.border_style }, )) - .header_style(self.colours.table_header_style) .style(self.colours.text_style) .widths( &(intrinsic_widths diff --git a/src/canvas/widgets/process_table.rs b/src/canvas/widgets/process_table.rs index f655b2c1..316e71ae 100644 --- a/src/canvas/widgets/process_table.rs +++ b/src/canvas/widgets/process_table.rs @@ -11,11 +11,10 @@ use tui::{ backend::Backend, layout::{Alignment, Constraint, Direction, Layout, Rect}, terminal::Frame, - text::{Span, Spans}, + text::{Span, Spans, Text}, widgets::{Block, Borders, Paragraph, Row, Table}, }; -use std::borrow::Cow; use unicode_segmentation::{GraphemeIndices, UnicodeSegmentation}; use unicode_width::UnicodeWidthStr; @@ -453,7 +452,7 @@ impl ProcessTableWidget for Painter { .collect::<Vec<&str>>(); if let Some(alternative) = alternative { - Cow::Borrowed(alternative) + Text::raw(alternative) } else if graphemes.len() > *calculated_col_width as usize && *calculated_col_width > 1 { @@ -461,33 +460,37 @@ impl ProcessTableWidget for Painter { let first_n = graphemes [..(*calculated_col_width as usize - 1)] .concat(); - Cow::Owned(format!("{}…", first_n)) + Text::raw(format!("{}…", first_n)) } else { - Cow::Borrowed(entry) + Text::raw(entry) } } else { - Cow::Borrowed(entry) + Text::raw(entry) } } else { - Cow::Borrowed(entry) + Text::raw(entry) } } else { - Cow::Borrowed(entry) + Text::raw(entry) } }, ); if *disabled { - Row::StyledData(truncated_data, self.colours.disabled_text_style) + Row::new(truncated_data).style(self.colours.disabled_text_style) } else { - Row::Data(truncated_data) + Row::new(truncated_data) } }); f.render_stateful_widget( - Table::new(process_headers.iter(), process_rows) + Table::new(process_rows) + .header( + Row::new(process_headers) + .style(self.colours.table_header_style) + .bottom_margin(table_gap), + ) .block(process_block) - .header_style(self.colours.table_header_style) .highlight_style(highlight_style) .style(self.colours.text_style) .widths( @@ -499,8 +502,7 @@ impl ProcessTableWidget for Painter { Constraint::Length(*calculated_width as u16) }) .collect::<Vec<_>>()), - ) - .header_gap(table_gap), + ), margined_draw_loc, proc_table_state, ); @@ -826,7 +828,7 @@ impl ProcessTableWidget for Painter { let sort_options = sliced_vec .iter() - .map(|column| Row::Data(vec![column].into_iter())); + .map(|column| Row::new(vec![column.as_str()])); let column_state = &mut proc_widget_state.columns.column_state; column_state.select(Some( @@ -872,13 +874,16 @@ impl ProcessTableWidget for Painter { .split(draw_loc)[0]; f.render_stateful_widget( - Table::new(["Sort By"].iter(), sort_options) + Table::new(sort_options) + .header( + Row::new(vec!["Sort By"]) + .style(self.colours.table_header_style) + .bottom_margin(table_gap), + ) .block(process_sort_block) .highlight_style(highlight_style) .style(self.colours.text_style) - .header_style(self.colours.table_header_style) - .widths(&[Constraint::Percentage(100)]) - .header_gap(table_gap), + .widths(&[Constraint::Percentage(100)]), margined_draw_loc, column_state, ); diff --git a/src/canvas/widgets/temp_table.rs b/src/canvas/widgets/temp_table.rs index f4e6a9c1..5347fb9d 100644 --- a/src/canvas/widgets/temp_table.rs +++ b/src/canvas/widgets/temp_table.rs @@ -4,7 +4,7 @@ use tui::{ layout::{Constraint, Direction, Layout, Rect}, terminal::Frame, text::Span, - text::Spans, + text::{Spans, Text}, widgets::{Block, Borders, Row, Table}, }; @@ -16,7 +16,6 @@ use crate::{ }, constants::*, }; -use std::borrow::Cow; use unicode_segmentation::UnicodeSegmentation; const TEMP_HEADERS: [&str; 2] = ["Sensor", "Temp"]; @@ -123,23 +122,23 @@ impl TempTableWidget for Painter { let first_n = graphemes [..(*calculated_col_width as usize - 1)] .concat(); - Cow::Owned(format!("{}…", first_n)) + Text::raw(format!("{}…", first_n)) } else { - Cow::Borrowed(entry) + Text::raw(entry) } } else { - Cow::Borrowed(entry) + Text::raw(entry) } } else { - Cow::Borrowed(entry) + Text::raw(entry) } } else { - Cow::Borrowed(entry) + Text::raw(entry) } }, ); - Row::Data(truncated_data) + Row::new(truncated_data) }); let (border_style, highlight_style) = if is_on_widget { @@ -230,9 +229,13 @@ impl TempTableWidget for Painter { // Draw f.render_stateful_widget( - Table::new(TEMP_HEADERS.iter(), temperature_rows) + Table::new(temperature_rows) + .header( + Row::new(TEMP_HEADERS.to_vec()) + .style(self.colours.table_header_style) + .bottom_margin(table_gap), + ) .block(temp_block) - .header_style(self.colours.table_header_style) .highlight_style(highlight_style) .style(self.colours.text_style) .widths( @@ -242,8 +245,7 @@ impl TempTableWidget for Painter { .iter() .map(|calculated_width| Constraint::Length(*calculated_width as u16)) .collect::<Vec<_>>()), - ) - .header_gap(table_gap), + ), margined_draw_loc, temp_table_state, ); @@ -75,13 +75,11 @@ pub fn handle_mouse_event(event: MouseEvent, app: &mut App) { MouseEvent::ScrollUp(_x, _y, _modifiers) => app.handle_scroll_up(), MouseEvent::ScrollDown(_x, _y, _modifiers) => app.handle_scroll_down(), MouseEvent::Down(button, x, y, _modifiers) => { - // debug!("Button down: {:?}, x: {}, y: {}", button, x, y); - if !app.app_config_fields.disable_click { match button { crossterm::event::MouseButton::Left => { // Trigger left click widget activity - app.left_mouse_click_movement(x, y); + app.on_left_mouse_up(x, y); } crossterm::event::MouseButton::Right => {} _ => {} |