summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2022-11-20 02:21:20 -0500
committerGitHub <noreply@github.com>2022-11-20 02:21:20 -0500
commit63df220a38b13999294fd1187bf72082ebdd4ec7 (patch)
treea0970b92e60bdc4bca35a958727bda2523cfd2e6 /src
parent6a0bf10760537193bb527d1ac0cd4ac13133da43 (diff)
other: clean up some strings (#904)
* other: clean up some strings * formatting
Diffstat (limited to 'src')
-rw-r--r--src/app/data_harvester.rs3
-rw-r--r--src/bin/main.rs3
-rw-r--r--src/canvas/canvas_colours.rs30
-rw-r--r--src/canvas/canvas_colours/colour_utils.rs78
-rw-r--r--src/canvas/widgets/battery_display.rs7
-rw-r--r--src/constants.rs392
-rw-r--r--src/data_conversion.rs4
-rw-r--r--src/options.rs46
-rw-r--r--src/utils/error.rs8
-rw-r--r--src/utils/gen_util.rs24
10 files changed, 287 insertions, 308 deletions
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs
index 25913077..c85f1b41 100644
--- a/src/app/data_harvester.rs
+++ b/src/app/data_harvester.rs
@@ -3,13 +3,10 @@
use std::time::Instant;
use futures::join;
-
#[cfg(target_os = "linux")]
use fxhash::FxHashMap;
-
#[cfg(feature = "battery")]
use starship_battery::{Battery, Manager};
-
#[cfg(not(target_os = "linux"))]
use sysinfo::{System, SystemExt};
diff --git a/src/bin/main.rs b/src/bin/main.rs
index 7168900b..84b91828 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -134,9 +134,10 @@ fn main() -> Result<()> {
#[cfg(target_os = "freebsd")]
let _stderr_fd = {
// A really ugly band-aid to suppress stderr warnings on FreeBSD due to sysinfo.
- use filedescriptor::{FileDescriptor, StdioDescriptor};
use std::fs::OpenOptions;
+ use filedescriptor::{FileDescriptor, StdioDescriptor};
+
let path = OpenOptions::new().write(true).open("/dev/null")?;
FileDescriptor::redirect_stdio(&path, StdioDescriptor::Stderr)?
};
diff --git a/src/canvas/canvas_colours.rs b/src/canvas/canvas_colours.rs
index 6a43a305..742bdb28 100644
--- a/src/canvas/canvas_colours.rs
+++ b/src/canvas/canvas_colours.rs
@@ -1,3 +1,5 @@
+use std::borrow::Cow;
+
use anyhow::Context;
use colour_utils::*;
use tui::style::{Color, Style};
@@ -45,15 +47,13 @@ impl Default for CanvasColours {
CanvasColours {
currently_selected_text_colour: Color::Black,
currently_selected_bg_colour: Color::Cyan,
- currently_selected_text_style: Style::default()
- .fg(Color::Black)
- .bg(STANDARD_HIGHLIGHT_COLOUR),
- table_header_style: Style::default().fg(STANDARD_HIGHLIGHT_COLOUR),
- ram_style: Style::default().fg(STANDARD_FIRST_COLOUR),
- swap_style: Style::default().fg(STANDARD_SECOND_COLOUR),
- arc_style: Style::default().fg(STANDARD_THIRD_COLOUR),
+ currently_selected_text_style: Style::default().fg(Color::Black).bg(HIGHLIGHT_COLOUR),
+ table_header_style: Style::default().fg(HIGHLIGHT_COLOUR),
+ ram_style: Style::default().fg(FIRST_COLOUR),
+ swap_style: Style::default().fg(SECOND_COLOUR),
+ arc_style: Style::default().fg(THIRD_COLOUR),
gpu_colour_styles: vec![
- Style::default().fg(STANDARD_FOURTH_COLOUR),
+ Style::default().fg(FOURTH_COLOUR),
Style::default().fg(Color::LightBlue),
Style::default().fg(Color::LightRed),
Style::default().fg(Color::Cyan),
@@ -61,10 +61,10 @@ impl Default for CanvasColours {
Style::default().fg(Color::Blue),
Style::default().fg(Color::Red),
],
- rx_style: Style::default().fg(STANDARD_FIRST_COLOUR),
- tx_style: Style::default().fg(STANDARD_SECOND_COLOUR),
- total_rx_style: Style::default().fg(STANDARD_THIRD_COLOUR),
- total_tx_style: Style::default().fg(STANDARD_FOURTH_COLOUR),
+ rx_style: Style::default().fg(FIRST_COLOUR),
+ tx_style: Style::default().fg(SECOND_COLOUR),
+ total_rx_style: Style::default().fg(THIRD_COLOUR),
+ total_tx_style: Style::default().fg(FOURTH_COLOUR),
all_colour_style: Style::default().fg(ALL_COLOUR),
avg_colour_style: Style::default().fg(AVG_COLOUR),
cpu_colour_styles: vec![
@@ -80,7 +80,7 @@ impl Default for CanvasColours {
Style::default().fg(Color::Red),
],
border_style: Style::default().fg(text_colour),
- highlighted_border_style: Style::default().fg(STANDARD_HIGHLIGHT_COLOUR),
+ highlighted_border_style: Style::default().fg(HIGHLIGHT_COLOUR),
text_style: Style::default().fg(text_colour),
widget_title_style: Style::default().fg(text_colour),
graph_style: Style::default().fg(text_colour),
@@ -283,7 +283,7 @@ impl CanvasColours {
Ok(())
}
- pub fn set_gpu_colours(&mut self, colours: &[String]) -> error::Result<()> {
+ pub fn set_gpu_colours(&mut self, colours: &[Cow<'static, str>]) -> error::Result<()> {
self.gpu_colour_styles = colours
.iter()
.map(|colour| get_style_from_config(colour))
@@ -321,7 +321,7 @@ impl CanvasColours {
Ok(())
}
- pub fn set_cpu_colours(&mut self, colours: &[String]) -> error::Result<()> {
+ pub fn set_cpu_colours(&mut self, colours: &[Cow<'static, str>]) -> error::Result<()> {
self.cpu_colour_styles = colours
.iter()
.map(|colour| get_style_from_config(colour))
diff --git a/src/canvas/canvas_colours/colour_utils.rs b/src/canvas/canvas_colours/colour_utils.rs
index 995bdb42..4948d5c4 100644
--- a/src/canvas/canvas_colours/colour_utils.rs
+++ b/src/canvas/canvas_colours/colour_utils.rs
@@ -1,44 +1,35 @@
-use std::collections::HashMap;
-
-use once_cell::sync::Lazy;
use tui::style::{Color, Style};
use crate::utils::error;
-// Approx, good enough for use (also Clippy gets mad if it's too long)
-pub const STANDARD_FIRST_COLOUR: Color = Color::LightMagenta;
-pub const STANDARD_SECOND_COLOUR: Color = Color::LightYellow;
-pub const STANDARD_THIRD_COLOUR: Color = Color::LightCyan;
-pub const STANDARD_FOURTH_COLOUR: Color = Color::LightGreen;
-pub const STANDARD_HIGHLIGHT_COLOUR: Color = Color::LightBlue;
+pub const FIRST_COLOUR: Color = Color::LightMagenta;
+pub const SECOND_COLOUR: Color = Color::LightYellow;
+pub const THIRD_COLOUR: Color = Color::LightCyan;
+pub const FOURTH_COLOUR: Color = Color::LightGreen;
+pub const HIGHLIGHT_COLOUR: Color = Color::LightBlue;
pub const AVG_COLOUR: Color = Color::Red;
pub const ALL_COLOUR: Color = Color::Green;
-static COLOR_NAME_LOOKUP_TABLE: Lazy<HashMap<&'static str, Color>> = Lazy::new(|| {
- [
- ("reset", Color::Reset),
- ("black", Color::Black),
- ("red", Color::Red),
- ("green", Color::Green),
- ("yellow", Color::Yellow),
- ("blue", Color::Blue),
- ("magenta", Color::Magenta),
- ("cyan", Color::Cyan),
- ("gray", Color::Gray),
- ("grey", Color::Gray),
- ("darkgray", Color::DarkGray),
- ("lightred", Color::LightRed),
- ("lightgreen", Color::LightGreen),
- ("lightyellow", Color::LightYellow),
- ("lightblue", Color::LightBlue),
- ("lightmagenta", Color::LightMagenta),
- ("lightcyan", Color::LightCyan),
- ("white", Color::White),
- ]
- .iter()
- .copied()
- .collect()
-});
+static COLOR_LOOKUP_TABLE: phf::Map<&'static str, Color> = phf::phf_map! {
+ "reset" => Color::Reset,
+ "black" => Color::Black,
+ "red" => Color::Red,
+ "green" => Color::Green,
+ "yellow" => Color::Yellow,
+ "blue" => Color::Blue,
+ "magenta" => Color::Magenta,
+ "cyan" => Color::Cyan,
+ "gray" => Color::Gray,
+ "grey" => Color::Gray,
+ "darkgray" => Color::DarkGray,
+ "lightred" => Color::LightRed,
+ "lightgreen" => Color::LightGreen,
+ "lightyellow" => Color::LightYellow,
+ "lightblue" => Color::LightBlue,
+ "lightmagenta" => Color::LightMagenta,
+ "lightcyan" => Color::LightCyan,
+ "white" => Color::White,
+};
pub fn convert_hex_to_color(hex: &str) -> error::Result<Color> {
fn hex_err(hex: &str) -> error::Result<u8> {
@@ -149,14 +140,12 @@ pub fn get_style_from_rgb(rgb_str: &str) -> error::Result<Style> {
}
fn convert_name_to_color(color_name: &str) -> error::Result<Color> {
- let color = COLOR_NAME_LOOKUP_TABLE.get(color_name.to_lowercase().as_str());
- if let Some(color) = color {
- return Ok(*color);
- }
-
- Err(error::BottomError::ConfigError(format!(
- "\"{}\" is an invalid named colour.
-
+ if let Some(color) = COLOR_LOOKUP_TABLE.get(color_name.to_lowercase().as_str()) {
+ Ok(*color)
+ } else {
+ Err(error::BottomError::ConfigError(format!(
+ "\"{}\" is an invalid named colour.
+
The following are supported strings:
+--------+------------+--------------+
| Reset | Magenta | LightYellow |
@@ -172,8 +161,9 @@ The following are supported strings:
| Blue | LightGreen | |
+--------+------------+--------------+
",
- color_name
- )))
+ color_name
+ )))
+ }
}
pub fn get_style_from_color_name(color_name: &str) -> error::Result<Style> {
diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs
index 3479f13f..a5ed507d 100644
--- a/src/canvas/widgets/battery_display.rs
+++ b/src/canvas/widgets/battery_display.rs
@@ -37,7 +37,7 @@ impl Painter {
let title = if app_state.is_expanded {
const TITLE_BASE: &str = " Battery ── Esc to go back ";
Spans::from(vec![
- Span::styled(" Battery ".to_string(), self.colours.widget_title_style),
+ Span::styled(" Battery ", self.colours.widget_title_style),
Span::styled(
format!(
"─{}─ Esc to go back ",
@@ -49,10 +49,7 @@ impl Painter {
),
])
} else {
- Spans::from(Span::styled(
- " Battery ".to_string(),
- self.colours.widget_title_style,
- ))
+ Spans::from(Span::styled(" Battery ", self.colours.widget_title_style))
};
let battery_block = if draw_border {
diff --git a/src/constants.rs b/src/constants.rs
index 4cdb1369..ceee7c4e 100644
--- a/src/constants.rs
+++ b/src/constants.rs
@@ -29,235 +29,235 @@ pub static DEFAULT_HEADER_STYLE: Lazy<tui::style::Style> =
// Colour profiles
pub static DEFAULT_LIGHT_MODE_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigColours {
- text_color: Some("black".to_string()),
- border_color: Some("black".to_string()),
- table_header_color: Some("black".to_string()),
- widget_title_color: Some("black".to_string()),
- selected_text_color: Some("white".to_string()),
- graph_color: Some("black".to_string()),
- disabled_text_color: Some("gray".to_string()),
- ram_color: Some("blue".to_string()),
- swap_color: Some("red".to_string()),
- arc_color: Some("LightBlue".to_string()),
+ text_color: Some("black".into()),
+ border_color: Some("black".into()),
+ table_header_color: Some("black".into()),
+ widget_title_color: Some("black".into()),
+ selected_text_color: Some("white".into()),
+ graph_color: Some("black".into()),
+ disabled_text_color: Some("gray".into()),
+ ram_color: Some("blue".into()),
+ swap_color: Some("red".into()),
+ arc_color: Some("LightBlue".into()),
gpu_core_colors: Some(vec![
- "LightGreen".to_string(),
- "LightCyan".to_string(),
- "LightRed".to_string(),
- "Cyan".to_string(),
- "Green".to_string(),
- "Blue".to_string(),
- "Red".to_string(),
+ "LightGreen".into(),
+ "LightCyan".into(),
+ "LightRed".into(),
+ "Cyan".into(),
+ "Green".into(),
+ "Blue".into(),
+ "Red".into(),
]),
- rx_color: Some("blue".to_string()),
- tx_color: Some("red".to_string()),
- rx_total_color: Some("LightBlue".to_string()),
- tx_total_color: Some("LightRed".to_string()),
+ rx_color: Some("blue".into()),
+ tx_color: Some("red".into()),
+ rx_total_color: Some("LightBlue".into()),
+ tx_total_color: Some("LightRed".into()),
cpu_core_colors: Some(vec![
- "LightMagenta".to_string(),
- "LightBlue".to_string(),
- "LightRed".to_string(),
- "Cyan".to_string(),
- "Green".to_string(),
- "Blue".to_string(),
- "Red".to_string(),
+ "LightMagenta".into(),
+ "LightBlue".into(),
+ "LightRed".into(),
+ "Cyan".into(),
+ "Green".into(),
+ "Blue".into(),
+ "Red".into(),
]),
..ConfigColours::default()
});
pub static GRUVBOX_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigColours {
- table_header_color: Some("#83a598".to_string()),
- all_cpu_color: Some("#8ec07c".to_string()),
- avg_cpu_color: Some("#fb4934".to_string()),
+ table_header_color: Some("#83a598".into()),
+ all_cpu_color: Some("#8ec07c".into()),
+ avg_cpu_color: Some("#fb4934".into()),
cpu_core_colors: Some(vec![
- "#cc241d".to_string(),
- "#98971a".to_string(),
- "#d79921".to_string(),
- "#458588".to_string(),
- "#b16286".to_string(),
- "#689d6a".to_string(),
- "#fe8019".to_string(),
- "#b8bb26".to_string(),
- "#fabd2f".to_string(),
- "#83a598".to_string(),
- "#d3869b".to_string(),
- "#d65d0e".to_string(),
- "#9d0006".to_string(),
- "#79740e".to_string(),
- "#b57614".to_string(),
- "#076678".to_string(),
- "#8f3f71".to_string(),
- "#427b58".to_string(),
- "#d65d03".to_string(),
- "#af3a03".to_string(),
+ "#cc241d".into(),
+ "#98971a".into(),
+ "#d79921".into(),
+ "#458588".into(),
+ "#b16286".into(),
+ "#689d6a".into(),
+ "#fe8019".into(),
+ "#b8bb26".into(),
+ "#fabd2f".into(),
+ "#83a598".into(),
+ "#d3869b".into(),
+ "#d65d0e".into(),
+ "#9d0006".into(),
+ "#79740e".into(),
+ "#b57614".into(),
+ "#076678".into(),
+ "#8f3f71".into(),
+ "#427b58".into(),
+ "#d65d03".into(),
+ "#af3a03".into(),
]),
- ram_color: Some("#8ec07c".to_string()),
- swap_color: Some("#fabd2f".to_string()),
- arc_color: Some("#689d6a".to_string()),
+ ram_color: Some("#8ec07c".into()),
+ swap_color: Some("#fabd2f".into()),
+ arc_color: Some("#689d6a".into()),
gpu_core_colors: Some(vec![
- "#d79921".to_string(),
- "#458588".to_string(),
- "#b16286".to_string(),
- "#fe8019".to_string(),
- "#b8bb26".to_string(),
- "#cc241d".to_string(),
- "#98971a".to_string(),
+ "#d79921".into(),
+ "#458588".into(),
+ "#b16286".into(),
+ "#fe8019".into(),
+ "#b8bb26".into(),
+ "#cc241d".into(),
+ "#98971a".into(),
]),
- rx_color: Some("#8ec07c".to_string()),
- tx_color: Some("#fabd2f".to_string()),
- rx_total_color: Some("#689d6a".to_string()),
- tx_total_color: Some("#d79921".to_string()),
- border_color: Some("#ebdbb2".to_string()),
- highlighted_border_color: Some("#fe8019".to_string()),
- disabled_text_color: Some("#665c54".to_string()),
- text_color: Some("#ebdbb2".to_string()),
- selected_text_color: Some("#1d2021".to_string()),
- selected_bg_color: Some("#ebdbb2".to_string()),
- widget_title_color: Some("#ebdbb2".to_string()),
- graph_color: Some("#ebdbb2".to_string()),
- high_battery_color: Some("#98971a".to_string()),
- medium_battery_color: Some("#fabd2f".to_string()),
- low_battery_color: Some("#fb4934".to_string()),
+ rx_color: Some("#8ec07c".into()),
+ tx_color: Some("#fabd2f".into()),
+ rx_total_color: Some("#689d6a".into()),
+ tx_total_color: Some("#d79921".into()),
+ border_color: Some("#ebdbb2".into()),
+ highlighted_border_color: Some("#fe8019".into()),
+ disabled_text_color: Some("#665c54".into()),
+ text_color: Some("#ebdbb2".into()),
+ selected_text_color: Some("#1d2021".into()),
+ selected_bg_color: Some("#ebdbb2".into()),
+ widget_title_color: Some("#ebdbb2".into()),
+ graph_color: Some("#ebdbb2".into()),
+ high_battery_color: Some("#98971a".into()),
+ medium_battery_color: Some("#fabd2f".into()),
+ low_battery_color: Some("#fb4934".into()),
});
pub static GRUVBOX_LIGHT_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigColours {
- table_header_color: Some("#076678".to_string()),
- all_cpu_color: Some("#8ec07c".to_string()),
- avg_cpu_color: Some("#fb4934".to_string()),
+ table_header_color: Some("#076678".into()),
+ all_cpu_color: Some("#8ec07c".into()),
+ avg_cpu_color: Some("#fb4934".into()),
cpu_core_colors: Some(vec![
- "#cc241d".to_string(),
- "#98971a".to_string(),
- "#d79921".to_string(),
- "#458588".to_string(),
- "#b16286".to_string(),
- "#689d6a".to_string(),
- "#fe8019".to_string(),
- "#b8bb26".to_string(),
- "#fabd2f".to_string(),
- "#83a598".to_string(),
- "#d3869b".to_string(),
- "#d65d0e".to_string(),
- "#9d0006".to_string(),
- "#79740e".to_string(),
- "#b57614".to_string(),
- "#076678".to_string(),
- "#8f3f71".to_string(),
- "#427b58".to_string(),
- "#d65d03".to_string(),
- "#af3a03".to_string(),
+ "#cc241d".into(),
+ "#98971a".into(),
+ "#d79921".into(),
+ "#458588".into(),
+ "#b16286".into(),
+ "#689d6a".into(),
+ "#fe8019".into(),
+ "#b8bb26".into(),
+ "#fabd2f".into(),
+ "#83a598".into(),
+ "#d3869b".into(),
+ "#d65d0e".into(),
+ "#9d0006".into(),
+ "#79740e".into(),
+ "#b57614".into(),
+ "#076678".into(),
+ "#8f3f71".into(),
+ "#427b58".into(),
+ "#d65d03".into(),
+ "#af3a03".into(),
]),
- ram_color: Some("#427b58".to_string()),
- swap_color: Some("#cc241d".to_string()),
- arc_color: Some("#689d6a".to_string()),
+ ram_color: Some("#427b58".into()),
+ swap_color: Some("#cc241d".into()),
+ arc_color: Some("#689d6a".into()),
gpu_core_colors: Some(vec![
- "#9d0006".to_string(),
- "#98971a".to_string(),
- "#d79921".to_string(),
- "#458588".to_string(),
- "#b16286".to_string(),
- "#fe8019".to_string(),
- "#b8bb26".to_string(),
+ "#9d0006".into(),
+ "#98971a".into(),
+ "#d79921".into(),
+ "#458588".into(),
+ "#b16286".into(),
+ "#fe8019".into(),
+ "#b8bb26".into(),
]),
- rx_color: Some("#427b58".to_string()),
- tx_color: Some("#cc241d".to_string()),
- rx_total_color: Some("#689d6a".to_string()),
- tx_total_color: Some("#9d0006".to_string()),
- border_color: Some("#3c3836".to_string()),
- highlighted_border_color: Some("#af3a03".to_string()),
- disabled_text_color: Some("#d5c4a1".to_string()),
- text_color: Some("#3c3836".to_string()),
- selected_text_color: Some("#ebdbb2".to_string()),
- selected_bg_color: Some("#3c3836".to_string()),
- widget_title_color: Some("#3c3836".to_string()),
- graph_color: Some("#3c3836".to_string()),
- high_battery_color: Some("#98971a".to_string()),
- medium_battery_color: Some("#d79921".to_string()),
- low_battery_color: Some("#cc241d".to_string()),
+ rx_color: Some("#427b58".into()),
+ tx_color: Some("#cc241d".into()),
+ rx_total_color: Some("#689d6a".into()),
+ tx_total_color: Some("#9d0006".into()),
+ border_color: Some("#3c3836".into()),
+ highlighted_border_color: Some("#af3a03".into()),
+ disabled_text_color: Some("#d5c4a1".into()),
+ text_color: Some("#3c3836".into()),
+ selected_text_color: Some("#ebdbb2".into()),
+ selected_bg_color: Some("#3c3836".into()),
+ widget_title_color: Some("#3c3836".into()),
+ graph_color: Some("#3c3836".into()),
+ high_battery_color: Some("#98971a".into()),
+ medium_battery_color: Some("#d79921".into()),
+ low_battery_color: Some("#cc241d".into()),
});
pub static NORD_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigColours {
- table_header_color: Some("#81a1c1".to_string()),
- all_cpu_color: Some("#88c0d0".to_string()),
- avg_cpu_color: Some("#8fbcbb".to_string()),
+ table_header_color: Some("#81a1c1".into()),
+ all_cpu_color: Some("#88c0d0".into()),
+ avg_cpu_color: Some("#8fbcbb".into()),
cpu_core_colors: Some(vec![
- "#5e81ac".to_string(),
- "#81a1c1".to_string(),
- "#d8dee9".to_string(),
- "#b48ead".to_string(),
- "#a3be8c".to_string(),
- "#ebcb8b".to_string(),
- "#d08770".to_string(),
- "#bf616a".to_string(),
+ "#5e81ac".into(),
+ "#81a1c1".into(),
+ "#d8dee9".into(),
+ "#b48ead".into(),
+ "#a3be8c".into(),
+ "#ebcb8b".into(),
+ "#d08770".into(),
+ "#bf616a".into(),
]),
- ram_color: Some("#88c0d0".to_string()),
- swap_color: Some("#d08770".to_string()),
- arc_color: Some("#5e81ac".to_string()),
+ ram_color: Some("#88c0d0".into()),
+ swap_color: Some("#d08770".into()),
+ arc_color: Some("#5e81ac".into()),
gpu_core_colors: Some(vec![
- "#8fbcbb".to_string(),
- "#81a1c1".to_string(),
- "#d8dee9".to_string(),
- "#b48ead".to_string(),
- "#a3be8c".to_string(),
- "#ebcb8b".to_string(),
- "#bf616a".to_string(),
+ "#8fbcbb".into(),
+ "#81a1c1".into(),
+ "#d8dee9".into(),
+ "#b48ead".into(),
+ "#a3be8c".into(),
+ "#ebcb8b".into(),
+ "#bf616a".into(),
]),
- rx_color: Some("#88c0d0".to_string()),
- tx_color: Some("#d08770".to_string()),
- rx_total_color: Some("#5e81ac".to_string()),
- tx_total_color: Some("#8fbcbb".to_string()),
- border_color: Some("#88c0d0".to_string()),
- highlighted_border_color: Some("#5e81ac".to_string()),
- disabled_text_color: Some("#4c566a".to_string()),
- text_color: Some("#e5e9f0".to_string()),
- selected_text_color: Some("#2e3440".to_string()),
- selected_bg_color: Some("#88c0d0".to_string()),
- widget_title_color: Some("#e5e9f0".to_string()),
- graph_color: Some("#e5e9f0".to_string()),
- high_battery_color: Some("#a3be8c".to_string()),
- medium_battery_color: Some("#ebcb8b".to_string()),
- low_battery_color: Some("#bf616a".to_string()),
+ rx_color: Some("#88c0d0".into()),
+ tx_color: Some("#d08770".into()),
+ rx_total_color: Some("#5e81ac".into()),
+ tx_total_color: Some("#8fbcbb".into()),
+ border_color: Some("#88c0d0".into()),
+ highlighted_border_color: Some("#5e81ac".into()),
+ disabled_text_color: Some("#4c566a".into()),
+ text_color: Some("#e5e9f0".into()),
+ selected_text_color: Some("#2e3440".into()),
+ selected_bg_color: Some("#88c0d0".into()),
+ widget_title_color: Some("#e5e9f0".into()),
+ graph_color: Some("#e5e9f0".into()),
+ high_battery_color: Some("#a3be8c".into()),
+ medium_battery_color: Some("#ebcb8b".into()),
+ low_battery_color: Some("#bf616a".into()),
});
pub static NORD_LIGHT_COLOUR_PALETTE: Lazy<ConfigColours> = Lazy::new(|| ConfigColours {
- table_header_color: Some("#5e81ac".to_string()),
- all_cpu_color: Some("#81a1c1".to_string()),
- avg_cpu_color: Some("#8fbcbb".to_string()),
+ table_header_color: Some("#5e81ac".into()),
+ all_cpu_color: Some("#81a1c1".into()),
+ avg_cpu_color: Some("#8fbcbb".into()),
cpu_core_colors: Some(vec![
- "#5e81ac".to_string(),
- "#88c0d0".to_string(),
- "#4c566a".to_string(),
- "#b48ead".to_string(),
- "#a3be8c".to_string(),
- "#ebcb8b".to_string(),
- "#d08770".to_string(),
- "#bf616a".to_string(),
+ "#5e81ac".into(),
+ "#88c0d0".into(),
+ "#4c566a".into(),
+ "#b48ead".into(),
+ "#a3be8c".into(),
+ "#ebcb8b".into(),
+ "#d08770".into(),
+ "#bf616a".into(),
]),
- ram_color: Some("#81a1c1".to_string()),
- swap_color: Some("#d08770".to_string()),
- arc_color: Some("#5e81ac".to_string()),
+ ram_color: Some("#81a1c1".into()),
+ swap_color: Some("#d08770".into()),
+ arc_color: Some("#5e81ac".into()),
gpu_core_colors: Some(vec![
- "#8fbcbb".to_string(),
- "#88c0d0".to_string(),
- "#4c566a".to_string(),
- "#b48ead".to_string(),
- "#a3be8c".to_string(),
- "#ebcb8b".to_string(),
- "#bf616a".to_string(),
+ "#8fbcbb".into(),
+ "#88c0d0".into(),
+ "#4c566a".into(),
+ "#b48ead".into(),
+ "#a3be8c".into(),
+ "#ebcb8b".into(),
+ "#bf616a".into(),
]),
- rx_color: Some("#81a1c1".to_string()),
- tx_color: Some("#d08770".to_string()),
- rx_total_color: Some("#5e81ac".to_string()),
- tx_total_color: Some("#8fbcbb".to_string()),
- border_color: Some("#2e3440".to_string()),
- highlighted_border_color: Some("#5e81ac".to_string()),
- disabled_text_color: Some("#d8dee9".to_string()),
- text_color: Some("#2e3440".to_string()),
- selected_text_color: Some("#f5f5f5".to_string()),
- selected_bg_color: Some("#5e81ac".to_string()),
- widget_title_color: Some("#2e3440".to_string()),
- graph_color: Some("#2e3440".to_string()),
- high_battery_color: Some("#a3be8c".to_string()),
- medium_battery_color: Some("#ebcb8b".to_string()),
- low_battery_color: Some("#bf616a".to_string()),
+ rx_color: Some("#81a1c1".into()),
+ tx_color: Some("#d08770".into()),
+ rx_total_color: Some("#5e81ac".into()),
+ tx_total_color: Some("#8fbcbb".into()),
+ border_color: Some("#2e3440".into()),
+ highlighted_border_color: Some("#5e81ac".into()),
+ disabled_text_color: Some("#d8dee9".into()),
+ text_color: Some("#2e3440".into()),
+ selected_text_color: Some("#f5f5f5".into()),
+ selected_bg_color: Some("#5e81ac".into()),
+ widget_title_color: Some("#2e3440".into()),
+ graph_color: Some("#2e3440".into()),
+ high_battery_color: Some("#a3be8c".into()),
+ medium_battery_color: Some("#ebcb8b".into()),
+ low_battery_color: Some("#bf616a".into()),
});
// Help text
diff --git a/src/data_conversion.rs b/src/data_conversion.rs
index 12f2dccd..4a529d71 100644
--- a/src/data_conversion.rs
+++ b/src/data_conversion.rs
@@ -371,7 +371,7 @@ pub fn convert_network_data_points(
),
};
- let (rx_converted_result, total_rx_converted_result): ((f64, String), (f64, String)) =
+ let (rx_converted_result, total_rx_converted_result): ((f64, String), (f64, &'static str)) =
if network_use_binary_prefix {
(
get_binary_prefix(rx_data, unit), // If this isn't obvious why there's two functions, one you can configure the unit, the other is always bytes
@@ -384,7 +384,7 @@ pub fn convert_network_data_points(
)
};
- let (tx_converted_result, total_tx_converted_result): ((f64, String), (f64, String)) =
+ let (tx_converted_result, total_tx_converted_result): ((f64, String), (f64, &'static str)) =
if network_use_binary_prefix {
(
get_binary_prefix(tx_data, unit),
diff --git a/src/options.rs b/src/options.rs
index 22491468..f2d8c0a8 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -114,29 +114,29 @@ impl WidgetIdEnabled {
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct ConfigColours {
- pub table_header_color: Option<String>,
- pub all_cpu_color: Option<String>,
- pub avg_cpu_color: Option<String>,
- pub cpu_core_colors: Option<Vec<String>>,
- pub ram_color: Option<String>,
- pub swap_color: Option<String>,
- pub arc_color: Option<String>,
- pub gpu_core_colors: Option<Vec<String>>,
- pub rx_color: Option<String>,
- pub tx_color: Option<String>,
- pub rx_total_color: Option<String>, // These only affect basic mode.
- pub tx_total_color: Option<String>, // These only affect basic mode.
- pub border_color: Option<String>,
- pub highlighted_border_color: Option<String>,
- pub disabled_text_color: Option<String>,
- pub text_color: Option<String>,
- pub selected_text_color: Option<String>,
- pub selected_bg_color: Option<String>,
- pub widget_title_color: Option<String>,
- pub graph_color: Option<String>,
- pub high_battery_color: Option<String>,
- pub medium_battery_color: Option<String>,
- pub low_battery_color: Option<String>,
+ pub table_header_color: Option<Cow<'static, str>>,
+ pub all_cpu_color: Option<Cow<'static, str>>,
+ pub avg_cpu_color: Option<Cow<'static, str>>,
+ pub cpu_core_colors: Option<Vec<Cow<'static, str>>>,
+ pub ram_color: Option<Cow<'static, str>>,
+ pub swap_color: Option<Cow<'static, str>>,
+ pub arc_color: Option<Cow<'static, str>>,
+ pub gpu_core_colors: Option<Vec<Cow<'static, str>>>,
+ pub rx_color: Option<Cow<'static, str>>,
+ pub tx_color: Option<Cow<'static, str>>,
+ pub rx_total_color: Option<Cow<'static, str>>, // These only affect basic mode.
+ pub tx_total_color: Option<Cow<'static, str>>, // These only affect basic mode.
+ pub border_color: Option<Cow<'static, str>>,
+ pub highlighted_border_color: Option<Cow<'static, str>>,
+ pub disabled_text_color: Option<Cow<'static, str>>,
+ pub text_color: Option<Cow<'static, str>>,
+ pub selected_text_color: Option<Cow<'static, str>>,
+ pub selected_bg_color: Option<Cow<'static, str>>,
+ pub widget_title_color: Option<Cow<'static, str>>,
+ pub graph_color: Option<Cow<'static, str>>,
+ pub high_battery_color: Option<Cow<'static, str>>,
+ pub medium_battery_color: Option<Cow<'static, str>>,
+ pub low_battery_color: Option<Cow<'static, str>>,
}
impl ConfigColours {
diff --git a/src/utils/error.rs b/src/utils/error.rs
index 603fabfc..fcb65e1b 100644
--- a/src/utils/error.rs
+++ b/src/utils/error.rs
@@ -100,13 +100,7 @@ impl From<regex::Error> for BottomError {
let err_str = err.to_string();
let error = err_str.split('\n').map(|s| s.trim()).collect::<Vec<_>>();
- BottomError::QueryError(
- format!(
- "Regex error: {}",
- error.last().unwrap_or(&"".to_string().as_str())
- )
- .into(),
- )
+ BottomError::QueryError(format!("Regex error: {}", error.last().unwrap_or(&"")).into())
}
}
diff --git a/src/utils/gen_util.rs b/src/utils/gen_util.rs
index 3a482937..ab8c8479 100644
--- a/src/utils/gen_util.rs
+++ b/src/utils/gen_util.rs
@@ -47,26 +47,26 @@ pub const LOG_TEBI_LIMIT_U32: u32 = 40;
/// Returns a tuple containing the value and the unit in bytes. In units of 1024.
/// This only supports up to a tebi. Note the "single" unit will have a space appended to match the others if
/// `spacing` is true.
-pub fn get_binary_bytes(bytes: u64) -> (f64, String) {
+pub fn get_binary_bytes(bytes: u64) -> (f64, &'static str) {
match bytes {
- b if b < KIBI_LIMIT => (bytes as f64, "B".to_string()),
- b if b < MEBI_LIMIT => (bytes as f64 / 1024.0, "KiB".to_string()),
- b if b < GIBI_LIMIT => (bytes as f64 / 1_048_576.0, "MiB".to_string()),
- b if b < TERA_LIMIT => (bytes as f64 / 1_073_741_824.0, "GiB".to_string()),
- _ => (bytes as f64 / 1_099_511_627_776.0, "TiB".to_string()),
+ b if b < KIBI_LIMIT => (bytes as f64, "B"),
+ b if b < MEBI_LIMIT => (bytes as f64 / 1024.0, "KiB"),
+ b if b < GIBI_LIMIT => (bytes as f64 / 1_048_576.0, "MiB"),
+ b if b < TERA_LIMIT => (bytes as f64 / 1_073_741_824.0, "GiB"),
+ _ => (bytes as f64 / 1_099_511_627_776.0, "TiB"),
}
}
/// Returns a tuple containing the value and the unit in bytes. In units of 1000.
/// This only supports up to a tera. Note the "single" unit will have a space appended to match the others if
/// `spacing` is true.
-pub fn get_decimal_bytes(bytes: u64) -> (f64, String) {
+pub fn get_decimal_bytes(bytes: u64) -> (f64, &'static str) {
match bytes {
- b if b < KILO_LIMIT => (bytes as f64, "B".to_string()),
- b if b < MEGA_LIMIT => (bytes as f64 / 1000.0, "KB".to_string()),
- b if b < GIGA_LIMIT => (bytes as f64 / 1_000_000.0, "MB".to_string()),
- b if b < TERA_LIMIT => (bytes as f64 / 1_000_000_000.0, "GB".to_string()),
- _ => (bytes as f64 / 1_000_000_000_000.0, "TB".to_string()),
+ b if b < KILO_LIMIT => (bytes as f64, "B"),
+ b if b < MEGA_LIMIT => (bytes as f64 / 1000.0, "KB"),
+ b if b < GIGA_LIMIT => (bytes as f64 / 1_000_000.0, "MB"),
+ b if b < TERA_LIMIT => (bytes as f64 / 1_000_000_000.0, "GB"),
+ _ => (bytes as f64 / 1_000_000_000_000.0, "TB"),
}
}