diff options
author | Mateusz Mikuła <mati865@gmail.com> | 2021-12-30 21:29:57 +0100 |
---|---|---|
committer | Mateusz Mikuła <mati865@gmail.com> | 2021-12-30 21:29:57 +0100 |
commit | e33d6b53611a96b325baf54709390ccc8321a7ce (patch) | |
tree | 0c8ea3306a91fc11aab40119adb5d44ec141e8d3 /src | |
parent | 6d4045a5f4bd2dd749b488b34c85f83d7221a6a6 (diff) |
Replace statics with consts where possible
Diffstat (limited to 'src')
-rw-r--r-- | src/canvas/widgets/battery_display.rs | 2 | ||||
-rw-r--r-- | src/canvas/widgets/cpu_basic.rs | 2 | ||||
-rw-r--r-- | src/canvas/widgets/disk_table.rs | 2 | ||||
-rw-r--r-- | src/canvas/widgets/mem_basic.rs | 2 | ||||
-rw-r--r-- | src/canvas/widgets/network_basic.rs | 2 | ||||
-rw-r--r-- | src/canvas/widgets/process_table.rs | 168 | ||||
-rw-r--r-- | src/canvas/widgets/temp_table.rs | 2 | ||||
-rw-r--r-- | src/constants.rs | 35 |
8 files changed, 99 insertions, 116 deletions
diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs index 52b769df..0ed06432 100644 --- a/src/canvas/widgets/battery_display.rs +++ b/src/canvas/widgets/battery_display.rs @@ -69,7 +69,7 @@ impl BatteryDisplayWidget for Painter { .border_style(border_style) } else if is_on_widget { Block::default() - .borders(*SIDE_BORDERS) + .borders(SIDE_BORDERS) .border_style(self.colours.highlighted_border_style) } else { Block::default().borders(Borders::NONE) diff --git a/src/canvas/widgets/cpu_basic.rs b/src/canvas/widgets/cpu_basic.rs index 5beb3f73..2c0da311 100644 --- a/src/canvas/widgets/cpu_basic.rs +++ b/src/canvas/widgets/cpu_basic.rs @@ -42,7 +42,7 @@ impl CpuBasicWidget for Painter { if app_state.current_widget.widget_id == widget_id { f.render_widget( Block::default() - .borders(*SIDE_BORDERS) + .borders(SIDE_BORDERS) .border_style(self.colours.highlighted_border_style), draw_loc, ); diff --git a/src/canvas/widgets/disk_table.rs b/src/canvas/widgets/disk_table.rs index fa7a9572..9833213d 100644 --- a/src/canvas/widgets/disk_table.rs +++ b/src/canvas/widgets/disk_table.rs @@ -226,7 +226,7 @@ impl DiskTableWidget for Painter { .border_style(border_style) } else if is_on_widget { Block::default() - .borders(*SIDE_BORDERS) + .borders(SIDE_BORDERS) .border_style(self.colours.highlighted_border_style) } else { Block::default().borders(Borders::NONE) diff --git a/src/canvas/widgets/mem_basic.rs b/src/canvas/widgets/mem_basic.rs index 3bb40ad7..cecb7b52 100644 --- a/src/canvas/widgets/mem_basic.rs +++ b/src/canvas/widgets/mem_basic.rs @@ -34,7 +34,7 @@ impl MemBasicWidget for Painter { if app_state.current_widget.widget_id == widget_id { f.render_widget( Block::default() - .borders(*SIDE_BORDERS) + .borders(SIDE_BORDERS) .border_style(self.colours.highlighted_border_style), draw_loc, ); diff --git a/src/canvas/widgets/network_basic.rs b/src/canvas/widgets/network_basic.rs index 7f0e393e..fdd5b08a 100644 --- a/src/canvas/widgets/network_basic.rs +++ b/src/canvas/widgets/network_basic.rs @@ -38,7 +38,7 @@ impl NetworkBasicWidget for Painter { if app_state.current_widget.widget_id == widget_id { f.render_widget( Block::default() - .borders(*SIDE_BORDERS) + .borders(SIDE_BORDERS) .border_style(self.colours.highlighted_border_style), draw_loc, ); diff --git a/src/canvas/widgets/process_table.rs b/src/canvas/widgets/process_table.rs index 0decebc9..c65fe62f 100644 --- a/src/canvas/widgets/process_table.rs +++ b/src/canvas/widgets/process_table.rs @@ -18,86 +18,74 @@ use tui::{ use unicode_segmentation::{GraphemeIndices, UnicodeSegmentation}; use unicode_width::UnicodeWidthStr; -use once_cell::sync::Lazy; - -static PROCESS_HEADERS_HARD_WIDTH_NO_GROUP: Lazy<Vec<Option<u16>>> = Lazy::new(|| { - vec![ - Some(7), - None, - Some(8), - Some(8), - Some(8), - Some(8), - Some(7), - Some(8), - #[cfg(target_family = "unix")] - None, - None, - ] -}); -static PROCESS_HEADERS_HARD_WIDTH_GROUPED: Lazy<Vec<Option<u16>>> = Lazy::new(|| { - vec![ - Some(7), - None, - Some(8), - Some(8), - Some(8), - Some(8), - Some(7), - Some(8), - ] -}); - -static PROCESS_HEADERS_SOFT_WIDTH_MAX_GROUPED_COMMAND: Lazy<Vec<Option<f64>>> = - Lazy::new(|| vec![None, Some(0.7), None, None, None, None, None, None]); -static PROCESS_HEADERS_SOFT_WIDTH_MAX_GROUPED_ELSE: Lazy<Vec<Option<f64>>> = - Lazy::new(|| vec![None, Some(0.3), None, None, None, None, None, None]); - -static PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_COMMAND: Lazy<Vec<Option<f64>>> = Lazy::new(|| { - vec![ - None, - Some(0.7), - None, - None, - None, - None, - None, - None, - #[cfg(target_family = "unix")] - Some(0.05), - Some(0.2), - ] -}); -static PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_TREE: Lazy<Vec<Option<f64>>> = Lazy::new(|| { - vec![ - None, - Some(0.5), - None, - None, - None, - None, - None, - None, - #[cfg(target_family = "unix")] - Some(0.05), - Some(0.2), - ] -}); -static PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_ELSE: Lazy<Vec<Option<f64>>> = Lazy::new(|| { - vec![ - None, - Some(0.3), - None, - None, - None, - None, - None, - None, - #[cfg(target_family = "unix")] - Some(0.05), - Some(0.2), - ] -}); +const PROCESS_HEADERS_HARD_WIDTH_NO_GROUP: &[Option<u16>] = &[ + Some(7), + None, + Some(8), + Some(8), + Some(8), + Some(8), + Some(7), + Some(8), + #[cfg(target_family = "unix")] + None, + None, +]; +const PROCESS_HEADERS_HARD_WIDTH_GROUPED: &[Option<u16>] = &[ + Some(7), + None, + Some(8), + Some(8), + Some(8), + Some(8), + Some(7), + Some(8), +]; + +const PROCESS_HEADERS_SOFT_WIDTH_MAX_GROUPED_COMMAND: &[Option<f64>] = + &[None, Some(0.7), None, None, None, None, None, None]; +const PROCESS_HEADERS_SOFT_WIDTH_MAX_GROUPED_ELSE: &[Option<f64>] = + &[None, Some(0.3), None, None, None, None, None, None]; + +const PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_COMMAND: &[Option<f64>] = &[ + None, + Some(0.7), + None, + None, + None, + None, + None, + None, + #[cfg(target_family = "unix")] + Some(0.05), + Some(0.2), +]; +const PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_TREE: &[Option<f64>] = &[ + None, + Some(0.5), + None, + None, + None, + None, + None, + None, + #[cfg(target_family = "unix")] + Some(0.05), + Some(0.2), +]; +const PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_ELSE: &[Option<f64>] = &[ + None, + Some(0.3), + None, + None, + None, + None, + None, + None, + #[cfg(target_family = "unix")] + Some(0.05), + Some(0.2), +]; pub trait ProcessTableWidget { /// Draws and handles all process-related drawing. Use this. @@ -291,7 +279,7 @@ impl ProcessTableWidget for Painter { .border_style(border_style) } else if is_on_widget { Block::default() - .borders(*SIDE_BORDERS) + .borders(SIDE_BORDERS) .border_style(self.colours.highlighted_border_style) } else { Block::default().borders(Borders::NONE) @@ -352,9 +340,9 @@ impl ProcessTableWidget for Painter { // Calculate widths // FIXME: See if we can move this into the recalculate block? I want to move column widths into the column widths let hard_widths = if proc_widget_state.is_grouped { - &*PROCESS_HEADERS_HARD_WIDTH_GROUPED + PROCESS_HEADERS_HARD_WIDTH_GROUPED } else { - &*PROCESS_HEADERS_HARD_WIDTH_NO_GROUP + PROCESS_HEADERS_HARD_WIDTH_NO_GROUP }; if recalculate_column_widths { @@ -404,16 +392,16 @@ impl ProcessTableWidget for Painter { // Note grouped trees are not a thing. if proc_widget_state.is_using_command { - &*PROCESS_HEADERS_SOFT_WIDTH_MAX_GROUPED_COMMAND + PROCESS_HEADERS_SOFT_WIDTH_MAX_GROUPED_COMMAND } else { - &*PROCESS_HEADERS_SOFT_WIDTH_MAX_GROUPED_ELSE + PROCESS_HEADERS_SOFT_WIDTH_MAX_GROUPED_ELSE } } else if proc_widget_state.is_using_command { - &*PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_COMMAND + PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_COMMAND } else if proc_widget_state.is_tree_mode { - &*PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_TREE + PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_TREE } else { - &*PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_ELSE + PROCESS_HEADERS_SOFT_WIDTH_MAX_NO_GROUP_ELSE }; proc_widget_state.table_width_state.calculated_column_widths = @@ -752,7 +740,7 @@ impl ProcessTableWidget for Painter { .border_style(current_border_style) } else if is_on_widget { Block::default() - .borders(*SIDE_BORDERS) + .borders(SIDE_BORDERS) .border_style(current_border_style) } else { Block::default().borders(Borders::NONE) @@ -863,7 +851,7 @@ impl ProcessTableWidget for Painter { .border_style(current_border_style) } else if is_on_widget { Block::default() - .borders(*SIDE_BORDERS) + .borders(SIDE_BORDERS) .border_style(current_border_style) } else { Block::default().borders(Borders::NONE) diff --git a/src/canvas/widgets/temp_table.rs b/src/canvas/widgets/temp_table.rs index fee35525..2ba0c61c 100644 --- a/src/canvas/widgets/temp_table.rs +++ b/src/canvas/widgets/temp_table.rs @@ -215,7 +215,7 @@ impl TempTableWidget for Painter { .border_style(border_style) } else if is_on_widget { Block::default() - .borders(*SIDE_BORDERS) + .borders(SIDE_BORDERS) .border_style(self.colours.highlighted_border_style) } else { Block::default().borders(Borders::NONE) diff --git a/src/constants.rs b/src/constants.rs index 48e115f7..8e5361ad 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -23,12 +23,9 @@ pub const TABLE_GAP_HEIGHT_LIMIT: u16 = 7; pub const TIME_LABEL_HEIGHT_LIMIT: u16 = 7; // Side borders -pub static SIDE_BORDERS: Lazy<tui::widgets::Borders> = - Lazy::new(|| tui::widgets::Borders::from_bits_truncate(20)); -pub static TOP_LEFT_RIGHT: Lazy<tui::widgets::Borders> = - Lazy::new(|| tui::widgets::Borders::from_bits_truncate(22)); -pub static BOTTOM_LEFT_RIGHT: Lazy<tui::widgets::Borders> = - Lazy::new(|| tui::widgets::Borders::from_bits_truncate(28)); +pub const SIDE_BORDERS: tui::widgets::Borders = tui::widgets::Borders::from_bits_truncate(20); +pub const TOP_LEFT_RIGHT: tui::widgets::Borders = tui::widgets::Borders::from_bits_truncate(22); +pub const BOTTOM_LEFT_RIGHT: tui::widgets::Borders = tui::widgets::Borders::from_bits_truncate(28); pub static DEFAULT_TEXT_STYLE: Lazy<tui::style::Style> = Lazy::new(|| tui::style::Style::default().fg(tui::style::Color::Gray)); pub static DEFAULT_HEADER_STYLE: Lazy<tui::style::Style> = @@ -359,18 +356,16 @@ pub const BASIC_MEM_HELP_TEXT: [&str; 2] = [ "% Toggle between values and percentages for memory usage", ]; -pub static HELP_TEXT: Lazy<Vec<Vec<&'static str>>> = Lazy::new(|| { - vec![ - HELP_CONTENTS_TEXT.to_vec(), - GENERAL_HELP_TEXT.to_vec(), - CPU_HELP_TEXT.to_vec(), - PROCESS_HELP_TEXT.to_vec(), - SEARCH_HELP_TEXT.to_vec(), - SORT_HELP_TEXT.to_vec(), - BATTERY_HELP_TEXT.to_vec(), - BASIC_MEM_HELP_TEXT.to_vec(), - ] -}); +pub const HELP_TEXT: &[&[&str]] = &[ + &HELP_CONTENTS_TEXT, + &GENERAL_HELP_TEXT, + &CPU_HELP_TEXT, + &PROCESS_HELP_TEXT, + &SEARCH_HELP_TEXT, + &SORT_HELP_TEXT, + &BATTERY_HELP_TEXT, + &BASIC_MEM_HELP_TEXT, +]; // Default layouts pub const DEFAULT_LAYOUT: &str = r##" @@ -546,7 +541,7 @@ pub const CONFIG_TEXT: &str = r##"# This is a default config file for bottom. A # [[row.child.child]] represents a widget. # # All widgets must have the type value set to one of ["cpu", "mem", "proc", "net", "temp", "disk", "empty"]. -# All layout components have a ratio value - if this is not set, then it defaults to 1. +# All layout components have a ratio value - if this is not set, then it defaults to 1. # The default widget layout: #[[row]] # ratio=30 @@ -631,7 +626,7 @@ pub const CONFIG_LAYOUT_HEAD: &str = r##" # [[row.child.child]] represents a widget. # # All widgets must have the valid type value set to one of ["cpu", "mem", "proc", "net", "temp", "disk", "empty"]. -# All layout components have a ratio value - if this is not set, then it defaults to 1. +# All layout components have a ratio value - if this is not set, then it defaults to 1. "##; pub const CONFIG_FILTER_HEAD: &str = r##" |