mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-10 14:44:18 +00:00
refactor: use macros for initializing canvas styles (#1149)
* refactor: use macros for initializing canvas styles * add quotes * Simplify macro * update tests * more renaming
This commit is contained in:
parent
bcca7e2621
commit
3a8d85d487
10 changed files with 131 additions and 273 deletions
|
@ -30,7 +30,7 @@ use crossterm::{
|
|||
use tui::{backend::CrosstermBackend, Terminal};
|
||||
|
||||
use bottom::{
|
||||
canvas::{self, canvas_styling::CanvasColours},
|
||||
canvas::{self, canvas_styling::CanvasStyling},
|
||||
constants::*,
|
||||
data_conversion::*,
|
||||
options::*,
|
||||
|
@ -66,9 +66,9 @@ fn main() -> Result<()> {
|
|||
.context("Found an issue while trying to build the widget layout.")?;
|
||||
|
||||
// FIXME: Should move this into build app or config
|
||||
let colours = {
|
||||
let styling = {
|
||||
let colour_scheme = get_color_scheme(&matches, &config)?;
|
||||
CanvasColours::new(colour_scheme, &config)?
|
||||
CanvasStyling::new(colour_scheme, &config)?
|
||||
};
|
||||
|
||||
// Create an "app" struct, which will control most of the program and store settings/state
|
||||
|
@ -78,11 +78,11 @@ fn main() -> Result<()> {
|
|||
&widget_layout,
|
||||
default_widget_id,
|
||||
&default_widget_type_option,
|
||||
&colours,
|
||||
&styling,
|
||||
)?;
|
||||
|
||||
// Create painter and set colours.
|
||||
let mut painter = canvas::Painter::init(widget_layout, colours)?;
|
||||
let mut painter = canvas::Painter::init(widget_layout, styling)?;
|
||||
|
||||
// Check if the current environment is in a terminal.
|
||||
check_if_terminal();
|
||||
|
|
|
@ -59,7 +59,7 @@ impl FromStr for ColourScheme {
|
|||
|
||||
/// Handles the canvas' state.
|
||||
pub struct Painter {
|
||||
pub colours: CanvasColours,
|
||||
pub colours: CanvasStyling,
|
||||
height: u16,
|
||||
width: u16,
|
||||
styled_help_text: Vec<Spans<'static>>,
|
||||
|
@ -82,7 +82,7 @@ enum LayoutConstraint {
|
|||
}
|
||||
|
||||
impl Painter {
|
||||
pub fn init(widget_layout: BottomLayout, colours: CanvasColours) -> anyhow::Result<Self> {
|
||||
pub fn init(widget_layout: BottomLayout, styling: CanvasStyling) -> anyhow::Result<Self> {
|
||||
// Now for modularity; we have to also initialize the base layouts!
|
||||
// We want to do this ONCE and reuse; after this we can just construct
|
||||
// based on the console size.
|
||||
|
@ -153,7 +153,7 @@ impl Painter {
|
|||
});
|
||||
|
||||
let mut painter = Painter {
|
||||
colours,
|
||||
colours: styling,
|
||||
height: 0,
|
||||
width: 0,
|
||||
styled_help_text: Vec::default(),
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use anyhow::Context;
|
||||
use colour_utils::*;
|
||||
use tui::style::{Color, Style};
|
||||
|
@ -12,7 +10,7 @@ use crate::{
|
|||
};
|
||||
mod colour_utils;
|
||||
|
||||
pub struct CanvasColours {
|
||||
pub struct CanvasStyling {
|
||||
pub currently_selected_text_colour: Color,
|
||||
pub currently_selected_bg_colour: Color,
|
||||
pub currently_selected_text_style: Style,
|
||||
|
@ -42,13 +40,13 @@ pub struct CanvasColours {
|
|||
pub disabled_text_style: Style,
|
||||
}
|
||||
|
||||
impl Default for CanvasColours {
|
||||
impl Default for CanvasStyling {
|
||||
fn default() -> Self {
|
||||
let text_colour = Color::Gray;
|
||||
let currently_selected_text_colour = Color::Black;
|
||||
let currently_selected_bg_colour = HIGHLIGHT_COLOUR;
|
||||
|
||||
CanvasColours {
|
||||
CanvasStyling {
|
||||
currently_selected_text_colour,
|
||||
currently_selected_bg_colour,
|
||||
currently_selected_text_style: Style::default()
|
||||
|
@ -99,7 +97,35 @@ impl Default for CanvasColours {
|
|||
}
|
||||
}
|
||||
|
||||
impl CanvasColours {
|
||||
macro_rules! try_set_colour {
|
||||
($field:expr, $colours:expr, $colour_field:ident) => {
|
||||
if let Some(colour_str) = &$colours.$colour_field {
|
||||
$field = str_to_fg(colour_str).context(concat!(
|
||||
"update '",
|
||||
stringify!($colour_field),
|
||||
"' in your config file"
|
||||
))?;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! try_set_colour_list {
|
||||
($field:expr, $colours:expr, $colour_field:ident) => {
|
||||
if let Some(colour_list) = &$colours.$colour_field {
|
||||
$field = colour_list
|
||||
.iter()
|
||||
.map(|s| str_to_fg(s))
|
||||
.collect::<error::Result<Vec<Style>>>()
|
||||
.context(concat!(
|
||||
"update '",
|
||||
stringify!($colour_field),
|
||||
"' in your config file"
|
||||
))?;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl CanvasStyling {
|
||||
pub fn new(colour_scheme: ColourScheme, config: &Config) -> anyhow::Result<Self> {
|
||||
let mut canvas_colours = Self::default();
|
||||
|
||||
|
@ -131,274 +157,91 @@ impl CanvasColours {
|
|||
}
|
||||
|
||||
pub fn set_colours_from_palette(&mut self, colours: &ConfigColours) -> anyhow::Result<()> {
|
||||
if let Some(border_color) = &colours.border_color {
|
||||
self.set_border_colour(border_color)
|
||||
.context("Update 'border_color' in your config file..")?;
|
||||
}
|
||||
|
||||
if let Some(highlighted_border_color) = &colours.highlighted_border_color {
|
||||
self.set_highlighted_border_colour(highlighted_border_color)
|
||||
.context("Update 'highlighted_border_color' in your config file..")?;
|
||||
}
|
||||
|
||||
if let Some(text_color) = &colours.text_color {
|
||||
self.set_text_colour(text_color)
|
||||
.context("Update 'text_color' in your config file..")?;
|
||||
}
|
||||
|
||||
if let Some(avg_cpu_color) = &colours.avg_cpu_color {
|
||||
self.set_avg_cpu_colour(avg_cpu_color)
|
||||
.context("Update 'avg_cpu_color' in your config file..")?;
|
||||
}
|
||||
|
||||
if let Some(all_cpu_color) = &colours.all_cpu_color {
|
||||
self.set_all_cpu_colour(all_cpu_color)
|
||||
.context("Update 'all_cpu_color' in your config file..")?;
|
||||
}
|
||||
|
||||
if let Some(cpu_core_colors) = &colours.cpu_core_colors {
|
||||
self.set_cpu_colours(cpu_core_colors)
|
||||
.context("Update 'cpu_core_colors' in your config file..")?;
|
||||
}
|
||||
|
||||
if let Some(ram_color) = &colours.ram_color {
|
||||
self.set_ram_colour(ram_color)
|
||||
.context("Update 'ram_color' in your config file..")?;
|
||||
}
|
||||
// CPU
|
||||
try_set_colour!(self.avg_colour_style, colours, avg_cpu_color);
|
||||
try_set_colour!(self.all_colour_style, colours, all_cpu_color);
|
||||
try_set_colour_list!(self.cpu_colour_styles, colours, cpu_core_colors);
|
||||
|
||||
// Memory
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
if let Some(cache_color) = &colours.cache_color {
|
||||
self.set_cache_colour(cache_color)
|
||||
.context("Update 'cache_color' in your config file..")?;
|
||||
}
|
||||
try_set_colour!(self.cache_style, colours, cache_color);
|
||||
|
||||
if let Some(swap_color) = &colours.swap_color {
|
||||
self.set_swap_colour(swap_color)
|
||||
.context("Update 'swap_color' in your config file..")?;
|
||||
}
|
||||
#[cfg(feature = "zfs")]
|
||||
try_set_colour!(self.arc_style, colours, arc_color);
|
||||
|
||||
if let Some(arc_color) = &colours.arc_color {
|
||||
self.set_arc_colour(arc_color)
|
||||
.context("Update 'arc_color' in your config file..")?;
|
||||
}
|
||||
#[cfg(feature = "gpu")]
|
||||
try_set_colour_list!(self.gpu_colour_styles, colours, gpu_core_colors);
|
||||
|
||||
if let Some(gpu_core_colors) = &colours.gpu_core_colors {
|
||||
self.set_gpu_colours(gpu_core_colors)
|
||||
.context("Update 'gpu_core_colors' in your config file..")?;
|
||||
}
|
||||
try_set_colour!(self.ram_style, colours, ram_color);
|
||||
try_set_colour!(self.swap_style, colours, swap_color);
|
||||
|
||||
if let Some(rx_color) = &colours.rx_color {
|
||||
self.set_rx_colour(rx_color)
|
||||
.context("Update 'rx_color' in your config file..")?;
|
||||
}
|
||||
// Network
|
||||
try_set_colour!(self.rx_style, colours, rx_color);
|
||||
try_set_colour!(self.tx_style, colours, tx_color);
|
||||
try_set_colour!(self.total_rx_style, colours, rx_total_color);
|
||||
try_set_colour!(self.total_tx_style, colours, tx_total_color);
|
||||
|
||||
if let Some(tx_color) = &colours.tx_color {
|
||||
self.set_tx_colour(tx_color)
|
||||
.context("Update 'tx_color' in your config file..")?;
|
||||
}
|
||||
// Battery
|
||||
try_set_colour!(self.high_battery_colour, colours, high_battery_color);
|
||||
try_set_colour!(self.medium_battery_colour, colours, medium_battery_color);
|
||||
try_set_colour!(self.low_battery_colour, colours, low_battery_color);
|
||||
|
||||
if let Some(table_header_color) = &colours.table_header_color {
|
||||
self.set_table_header_colour(table_header_color)
|
||||
.context("Update 'table_header_color' in your config file..")?;
|
||||
}
|
||||
// Widget text and graphs
|
||||
try_set_colour!(self.widget_title_style, colours, widget_title_color);
|
||||
try_set_colour!(self.graph_style, colours, graph_color);
|
||||
try_set_colour!(self.text_style, colours, text_color);
|
||||
try_set_colour!(self.disabled_text_style, colours, disabled_text_color);
|
||||
try_set_colour!(self.border_style, colours, border_color);
|
||||
try_set_colour!(
|
||||
self.highlighted_border_style,
|
||||
colours,
|
||||
highlighted_border_color
|
||||
);
|
||||
|
||||
// Tables
|
||||
try_set_colour!(self.table_header_style, colours, table_header_color);
|
||||
|
||||
if let Some(scroll_entry_text_color) = &colours.selected_text_color {
|
||||
self.set_scroll_entry_text_color(scroll_entry_text_color)
|
||||
.context("Update 'selected_text_color' in your config file..")?;
|
||||
.context("update 'selected_text_color' in your config file")?;
|
||||
}
|
||||
|
||||
if let Some(scroll_entry_bg_color) = &colours.selected_bg_color {
|
||||
self.set_scroll_entry_bg_color(scroll_entry_bg_color)
|
||||
.context("Update 'selected_bg_color' in your config file..")?;
|
||||
}
|
||||
|
||||
if let Some(widget_title_color) = &colours.widget_title_color {
|
||||
self.set_widget_title_colour(widget_title_color)
|
||||
.context("Update 'widget_title_color' in your config file..")?;
|
||||
}
|
||||
|
||||
if let Some(graph_color) = &colours.graph_color {
|
||||
self.set_graph_colour(graph_color)
|
||||
.context("Update 'graph_color' in your config file..")?;
|
||||
}
|
||||
|
||||
if let Some(high_battery_color) = &colours.high_battery_color {
|
||||
self.set_high_battery_color(high_battery_color)
|
||||
.context("Update 'high_battery_color' in your config file.")?;
|
||||
}
|
||||
|
||||
if let Some(medium_battery_color) = &colours.medium_battery_color {
|
||||
self.set_medium_battery_color(medium_battery_color)
|
||||
.context("Update 'medium_battery_color' in your config file.")?;
|
||||
}
|
||||
|
||||
if let Some(low_battery_color) = &colours.low_battery_color {
|
||||
self.set_low_battery_color(low_battery_color)
|
||||
.context("Update 'low_battery_color' in your config file.")?;
|
||||
}
|
||||
|
||||
if let Some(disabled_text_color) = &colours.disabled_text_color {
|
||||
self.set_disabled_text_colour(disabled_text_color)
|
||||
.context("Update 'disabled_text_color' in your config file.")?;
|
||||
}
|
||||
|
||||
if let Some(rx_total_color) = &colours.rx_total_color {
|
||||
self.set_rx_total_colour(rx_total_color)?;
|
||||
}
|
||||
|
||||
if let Some(tx_total_color) = &colours.tx_total_color {
|
||||
self.set_tx_total_colour(tx_total_color)?;
|
||||
.context("update 'selected_bg_color' in your config file")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_disabled_text_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.disabled_text_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_text_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.text_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_border_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.border_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_highlighted_border_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.highlighted_border_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_table_header_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.table_header_style = str_to_fg(colour)?;
|
||||
// Disabled as it seems to be bugged when I go into full command mode...? It becomes huge lol
|
||||
// self.table_header_style = get_style_from_config(colour)?.modifier(Modifier::BOLD);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_ram_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.ram_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
pub fn set_cache_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.cache_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_swap_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.swap_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_arc_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.arc_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_gpu_colours(&mut self, colours: &[Cow<'static, str>]) -> error::Result<()> {
|
||||
self.gpu_colour_styles = colours
|
||||
.iter()
|
||||
.map(|colour| str_to_fg(colour))
|
||||
.collect::<error::Result<Vec<Style>>>()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_rx_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.rx_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_tx_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.tx_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_rx_total_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.total_rx_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_tx_total_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.total_tx_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_avg_cpu_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.avg_colour_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_all_cpu_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.all_colour_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_cpu_colours(&mut self, colours: &[Cow<'static, str>]) -> error::Result<()> {
|
||||
self.cpu_colour_styles = colours
|
||||
.iter()
|
||||
.map(|colour| str_to_fg(colour))
|
||||
.collect::<error::Result<Vec<Style>>>()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_scroll_entry_text_color(&mut self, colour: &str) -> error::Result<()> {
|
||||
fn set_scroll_entry_text_color(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.currently_selected_text_colour = str_to_colour(colour)?;
|
||||
self.currently_selected_text_style = Style::default()
|
||||
.fg(self.currently_selected_text_colour)
|
||||
.bg(self.currently_selected_bg_colour);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_scroll_entry_bg_color(&mut self, colour: &str) -> error::Result<()> {
|
||||
fn set_scroll_entry_bg_color(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.currently_selected_bg_colour = str_to_colour(colour)?;
|
||||
self.currently_selected_text_style = Style::default()
|
||||
.fg(self.currently_selected_text_colour)
|
||||
.bg(self.currently_selected_bg_colour);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_widget_title_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.widget_title_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_graph_colour(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.graph_style = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_high_battery_color(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.high_battery_colour = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_medium_battery_color(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.medium_battery_colour = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_low_battery_color(&mut self, colour: &str) -> error::Result<()> {
|
||||
self.low_battery_colour = str_to_fg(colour)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use super::{CanvasColours, ColourScheme};
|
||||
use super::{CanvasStyling, ColourScheme};
|
||||
use crate::Config;
|
||||
use tui::style::{Color, Style};
|
||||
|
||||
#[test]
|
||||
fn default_selected_colour_works() {
|
||||
let mut colours = CanvasColours::default();
|
||||
let mut colours = CanvasStyling::default();
|
||||
|
||||
assert_eq!(
|
||||
colours.currently_selected_text_style,
|
||||
|
@ -408,7 +251,6 @@ mod test {
|
|||
);
|
||||
|
||||
colours.set_scroll_entry_text_color("red").unwrap();
|
||||
|
||||
assert_eq!(
|
||||
colours.currently_selected_text_style,
|
||||
Style::default()
|
||||
|
@ -417,7 +259,22 @@ mod test {
|
|||
);
|
||||
|
||||
colours.set_scroll_entry_bg_color("magenta").unwrap();
|
||||
assert_eq!(
|
||||
colours.currently_selected_text_style,
|
||||
Style::default().fg(Color::Red).bg(Color::Magenta),
|
||||
);
|
||||
|
||||
colours.set_scroll_entry_text_color("fake red").unwrap_err();
|
||||
assert_eq!(
|
||||
colours.currently_selected_text_style,
|
||||
Style::default()
|
||||
.fg(Color::Red)
|
||||
.bg(colours.currently_selected_bg_colour),
|
||||
);
|
||||
|
||||
colours
|
||||
.set_scroll_entry_bg_color("fake magenta")
|
||||
.unwrap_err();
|
||||
assert_eq!(
|
||||
colours.currently_selected_text_style,
|
||||
Style::default().fg(Color::Red).bg(Color::Magenta),
|
||||
|
@ -425,13 +282,13 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_built_in_colour_schemes() {
|
||||
fn built_in_colour_schemes_work() {
|
||||
let config = Config::default();
|
||||
CanvasColours::new(ColourScheme::Default, &config).unwrap();
|
||||
CanvasColours::new(ColourScheme::DefaultLight, &config).unwrap();
|
||||
CanvasColours::new(ColourScheme::Gruvbox, &config).unwrap();
|
||||
CanvasColours::new(ColourScheme::GruvboxLight, &config).unwrap();
|
||||
CanvasColours::new(ColourScheme::Nord, &config).unwrap();
|
||||
CanvasColours::new(ColourScheme::NordLight, &config).unwrap();
|
||||
CanvasStyling::new(ColourScheme::Default, &config).unwrap();
|
||||
CanvasStyling::new(ColourScheme::DefaultLight, &config).unwrap();
|
||||
CanvasStyling::new(ColourScheme::Gruvbox, &config).unwrap();
|
||||
CanvasStyling::new(ColourScheme::GruvboxLight, &config).unwrap();
|
||||
CanvasStyling::new(ColourScheme::Nord, &config).unwrap();
|
||||
CanvasStyling::new(ColourScheme::NordLight, &config).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,6 +200,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn valid_hex_colours() {
|
||||
// Check hex with 6 characters.
|
||||
assert_eq!(
|
||||
convert_hex_to_color("#ffffff").unwrap(),
|
||||
Color::Rgb(255, 255, 255)
|
||||
|
@ -216,6 +217,7 @@ mod test {
|
|||
Color::Rgb(18, 58, 188)
|
||||
);
|
||||
|
||||
// Check hex with 3 characters.
|
||||
assert_eq!(
|
||||
convert_hex_to_color("#fff").unwrap(),
|
||||
Color::Rgb(255, 255, 255)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use tui::style::Style;
|
||||
|
||||
use crate::canvas::canvas_styling::CanvasColours;
|
||||
use crate::canvas::canvas_styling::CanvasStyling;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DataTableStyling {
|
||||
|
@ -13,7 +13,7 @@ pub struct DataTableStyling {
|
|||
}
|
||||
|
||||
impl DataTableStyling {
|
||||
pub fn from_colours(colours: &CanvasColours) -> Self {
|
||||
pub fn from_colours(colours: &CanvasStyling) -> Self {
|
||||
Self {
|
||||
header_style: colours.table_header_style,
|
||||
border_style: colours.border_style,
|
||||
|
|
|
@ -18,7 +18,7 @@ use starship_battery::Manager;
|
|||
|
||||
use crate::{
|
||||
app::{filter::Filter, layout_manager::*, *},
|
||||
canvas::{canvas_styling::CanvasColours, ColourScheme},
|
||||
canvas::{canvas_styling::CanvasStyling, ColourScheme},
|
||||
constants::*,
|
||||
units::data_units::DataUnit,
|
||||
utils::error::{self, BottomError},
|
||||
|
@ -172,7 +172,7 @@ macro_rules! is_flag_enabled {
|
|||
pub fn build_app(
|
||||
matches: &ArgMatches, config: &mut Config, widget_layout: &BottomLayout,
|
||||
default_widget_id: u64, default_widget_type_option: &Option<BottomWidgetType>,
|
||||
colours: &CanvasColours,
|
||||
styling: &CanvasStyling,
|
||||
) -> Result<App> {
|
||||
use BottomWidgetType::*;
|
||||
|
||||
|
@ -321,7 +321,7 @@ pub fn build_app(
|
|||
&app_config_fields,
|
||||
default_time_value,
|
||||
autohide_timer,
|
||||
colours,
|
||||
styling,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ pub fn build_app(
|
|||
&app_config_fields,
|
||||
mode,
|
||||
table_config,
|
||||
colours,
|
||||
styling,
|
||||
&proc_columns,
|
||||
),
|
||||
);
|
||||
|
@ -362,13 +362,13 @@ pub fn build_app(
|
|||
Disk => {
|
||||
disk_state_map.insert(
|
||||
widget.widget_id,
|
||||
DiskTableWidget::new(&app_config_fields, colours),
|
||||
DiskTableWidget::new(&app_config_fields, styling),
|
||||
);
|
||||
}
|
||||
Temp => {
|
||||
temp_state_map.insert(
|
||||
widget.widget_id,
|
||||
TempWidgetState::new(&app_config_fields, colours),
|
||||
TempWidgetState::new(&app_config_fields, styling),
|
||||
);
|
||||
}
|
||||
Battery => {
|
||||
|
@ -868,18 +868,17 @@ fn get_retention_ms(matches: &ArgMatches, config: &Config) -> error::Result<u64>
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use clap::ArgMatches;
|
||||
|
||||
use super::{get_color_scheme, get_widget_layout, Config};
|
||||
use crate::{app::App, canvas::canvas_styling::CanvasColours};
|
||||
use crate::{app::App, canvas::canvas_styling::CanvasStyling};
|
||||
|
||||
fn create_app(mut config: Config, matches: ArgMatches) -> App {
|
||||
let (layout, id, ty) = get_widget_layout(&matches, &config).unwrap();
|
||||
let colours =
|
||||
CanvasColours::new(get_color_scheme(&matches, &config).unwrap(), &config).unwrap();
|
||||
let styling =
|
||||
CanvasStyling::new(get_color_scheme(&matches, &config).unwrap(), &config).unwrap();
|
||||
|
||||
super::build_app(&matches, &mut config, &layout, id, &ty, &colours).unwrap()
|
||||
super::build_app(&matches, &mut config, &layout, id, &ty, &styling).unwrap()
|
||||
}
|
||||
|
||||
// TODO: There's probably a better way to create clap options AND unify together to avoid the possibility of
|
||||
|
|
|
@ -5,7 +5,7 @@ use tui::{style::Style, text::Text, widgets::Row};
|
|||
|
||||
use crate::{
|
||||
app::{data_harvester::cpu::CpuDataType, AppConfigFields},
|
||||
canvas::{canvas_styling::CanvasColours, Painter},
|
||||
canvas::{canvas_styling::CanvasStyling, Painter},
|
||||
components::data_table::{
|
||||
Column, ColumnHeader, DataTable, DataTableColumn, DataTableProps, DataTableStyling,
|
||||
DataToCell,
|
||||
|
@ -22,7 +22,7 @@ pub struct CpuWidgetStyling {
|
|||
}
|
||||
|
||||
impl CpuWidgetStyling {
|
||||
fn from_colours(colours: &CanvasColours) -> Self {
|
||||
fn from_colours(colours: &CanvasStyling) -> Self {
|
||||
let entries = if colours.cpu_colour_styles.is_empty() {
|
||||
vec![Style::default()]
|
||||
} else {
|
||||
|
@ -166,7 +166,7 @@ pub struct CpuWidgetState {
|
|||
impl CpuWidgetState {
|
||||
pub fn new(
|
||||
config: &AppConfigFields, current_display_time: u64, autohide_timer: Option<Instant>,
|
||||
colours: &CanvasColours,
|
||||
colours: &CanvasStyling,
|
||||
) -> Self {
|
||||
const COLUMNS: [Column<CpuWidgetColumn>; 2] = [
|
||||
Column::soft(CpuWidgetColumn::CPU, Some(0.5)),
|
||||
|
|
|
@ -5,7 +5,7 @@ use tui::text::Text;
|
|||
|
||||
use crate::{
|
||||
app::AppConfigFields,
|
||||
canvas::canvas_styling::CanvasColours,
|
||||
canvas::canvas_styling::CanvasStyling,
|
||||
components::data_table::{
|
||||
ColumnHeader, DataTableColumn, DataTableProps, DataTableStyling, DataToCell, SortColumn,
|
||||
SortDataTable, SortDataTableProps, SortOrder, SortsRow,
|
||||
|
@ -213,7 +213,7 @@ impl SortsRow for DiskWidgetColumn {
|
|||
}
|
||||
|
||||
impl DiskTableWidget {
|
||||
pub fn new(config: &AppConfigFields, colours: &CanvasColours) -> Self {
|
||||
pub fn new(config: &AppConfigFields, colours: &CanvasStyling) -> Self {
|
||||
let columns = [
|
||||
SortColumn::soft(DiskWidgetColumn::Disk, Some(0.2)),
|
||||
SortColumn::soft(DiskWidgetColumn::Mount, Some(0.2)),
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
query::*,
|
||||
AppConfigFields, AppSearchState,
|
||||
},
|
||||
canvas::canvas_styling::CanvasColours,
|
||||
canvas::canvas_styling::CanvasStyling,
|
||||
components::data_table::{
|
||||
Column, ColumnHeader, ColumnWidthBounds, DataTable, DataTableColumn, DataTableProps,
|
||||
DataTableStyling, SortColumn, SortDataTable, SortDataTableProps, SortOrder, SortsRow,
|
||||
|
@ -177,7 +177,7 @@ pub struct ProcWidgetState {
|
|||
}
|
||||
|
||||
impl ProcWidgetState {
|
||||
fn new_sort_table(config: &AppConfigFields, colours: &CanvasColours) -> SortTable {
|
||||
fn new_sort_table(config: &AppConfigFields, colours: &CanvasStyling) -> SortTable {
|
||||
const COLUMNS: [Column<SortTableColumn>; 1] = [Column::hard(SortTableColumn, 7)];
|
||||
|
||||
let props = DataTableProps {
|
||||
|
@ -194,7 +194,7 @@ impl ProcWidgetState {
|
|||
}
|
||||
|
||||
fn new_process_table(
|
||||
config: &AppConfigFields, colours: &CanvasColours, columns: Vec<SortColumn<ProcColumn>>,
|
||||
config: &AppConfigFields, colours: &CanvasStyling, columns: Vec<SortColumn<ProcColumn>>,
|
||||
default_index: usize, default_order: SortOrder,
|
||||
) -> ProcessTable {
|
||||
let inner_props = DataTableProps {
|
||||
|
@ -217,7 +217,7 @@ impl ProcWidgetState {
|
|||
|
||||
pub fn new(
|
||||
config: &AppConfigFields, mode: ProcWidgetMode, table_config: ProcTableConfig,
|
||||
colours: &CanvasColours, config_columns: &Option<IndexSet<ProcWidgetColumn>>,
|
||||
colours: &CanvasStyling, config_columns: &Option<IndexSet<ProcWidgetColumn>>,
|
||||
) -> Self {
|
||||
let process_search_state = {
|
||||
let mut pss = ProcessSearchState::default();
|
||||
|
@ -1119,14 +1119,14 @@ mod test {
|
|||
|
||||
fn init_state(table_config: ProcTableConfig, columns: &[ProcWidgetColumn]) -> ProcWidgetState {
|
||||
let config = AppConfigFields::default();
|
||||
let colours = CanvasColours::default();
|
||||
let styling = CanvasStyling::default();
|
||||
let columns = Some(columns.iter().cloned().collect());
|
||||
|
||||
ProcWidgetState::new(
|
||||
&config,
|
||||
ProcWidgetMode::Normal,
|
||||
table_config,
|
||||
&colours,
|
||||
&styling,
|
||||
&columns,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use tui::text::Text;
|
|||
|
||||
use crate::{
|
||||
app::{data_harvester::temperature::TemperatureType, AppConfigFields},
|
||||
canvas::canvas_styling::CanvasColours,
|
||||
canvas::canvas_styling::CanvasStyling,
|
||||
components::data_table::{
|
||||
ColumnHeader, DataTableColumn, DataTableProps, DataTableStyling, DataToCell, SortColumn,
|
||||
SortDataTable, SortDataTableProps, SortOrder, SortsRow,
|
||||
|
@ -99,7 +99,7 @@ pub struct TempWidgetState {
|
|||
}
|
||||
|
||||
impl TempWidgetState {
|
||||
pub fn new(config: &AppConfigFields, colours: &CanvasColours) -> Self {
|
||||
pub fn new(config: &AppConfigFields, colours: &CanvasStyling) -> Self {
|
||||
let columns = [
|
||||
SortColumn::soft(TempWidgetColumn::Sensor, Some(0.8)),
|
||||
SortColumn::soft(TempWidgetColumn::Temp, None).default_descending(),
|
||||
|
|
Loading…
Reference in a new issue