summaryrefslogtreecommitdiffstats
path: root/src/canvas.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/canvas.rs')
-rw-r--r--src/canvas.rs140
1 files changed, 136 insertions, 4 deletions
diff --git a/src/canvas.rs b/src/canvas.rs
index 63e258f4..f4707507 100644
--- a/src/canvas.rs
+++ b/src/canvas.rs
@@ -1,3 +1,4 @@
+use anyhow::Context;
use itertools::izip;
use std::collections::HashMap;
@@ -10,6 +11,7 @@ use tui::{
use canvas_colours::*;
use dialogs::*;
+use screens::*;
use widgets::*;
use crate::{
@@ -20,12 +22,14 @@ use crate::{
},
constants::*,
data_conversion::{ConvertedBatteryData, ConvertedCpuData, ConvertedProcessData},
+ options::Config,
utils::error,
};
mod canvas_colours;
mod dialogs;
mod drawing_utils;
+mod screens;
mod widgets;
/// Point is of time, data
@@ -65,13 +69,15 @@ pub struct Painter {
col_constraints: Vec<Vec<Constraint>>,
col_row_constraints: Vec<Vec<Vec<Constraint>>>,
layout_constraints: Vec<Vec<Vec<Vec<Constraint>>>>,
- widget_layout: BottomLayout,
derived_widget_draw_locs: Vec<Vec<Vec<Vec<Rect>>>>,
+ widget_layout: BottomLayout,
table_height_offset: u16,
}
impl Painter {
- pub fn init(widget_layout: BottomLayout, table_gap: u16, is_basic_mode: bool) -> Self {
+ pub fn init(
+ widget_layout: BottomLayout, table_gap: u16, is_basic_mode: bool, config: &Config,
+ ) -> 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.
@@ -139,7 +145,7 @@ impl Painter {
col_constraints.push(new_col_constraints);
});
- Painter {
+ let mut painter = Painter {
colours: CanvasColours::default(),
height: 0,
width: 0,
@@ -152,12 +158,128 @@ impl Painter {
widget_layout,
derived_widget_draw_locs: Vec::default(),
table_height_offset: if is_basic_mode { 2 } else { 4 } + table_gap,
+ };
+
+ painter.generate_config_colours(config)?;
+ painter.colours.generate_remaining_cpu_colours();
+ painter.complete_painter_init();
+
+ Ok(painter)
+ }
+
+ pub fn generate_config_colours(&mut self, config: &Config) -> anyhow::Result<()> {
+ if let Some(colours) = &config.colors {
+ if let Some(border_color) = &colours.border_color {
+ self.colours
+ .set_border_colour(border_color)
+ .context("Update 'border_color' in your config file..")?;
+ }
+
+ if let Some(highlighted_border_color) = &colours.highlighted_border_color {
+ self.colours
+ .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.colours
+ .set_text_colour(text_color)
+ .context("Update 'text_color' in your config file..")?;
+ }
+
+ if let Some(avg_cpu_color) = &colours.avg_cpu_color {
+ self.colours
+ .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.colours
+ .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.colours
+ .set_cpu_colours(cpu_core_colors)
+ .context("Update 'cpu_core_colors' in your config file..")?;
+ }
+
+ if let Some(ram_color) = &colours.ram_color {
+ self.colours
+ .set_ram_colour(ram_color)
+ .context("Update 'ram_color' in your config file..")?;
+ }
+
+ if let Some(swap_color) = &colours.swap_color {
+ self.colours
+ .set_swap_colour(swap_color)
+ .context("Update 'swap_color' in your config file..")?;
+ }
+
+ if let Some(rx_color) = &colours.rx_color {
+ self.colours
+ .set_rx_colour(rx_color)
+ .context("Update 'rx_color' in your config file..")?;
+ }
+
+ if let Some(tx_color) = &colours.tx_color {
+ self.colours
+ .set_tx_colour(tx_color)
+ .context("Update 'tx_color' in your config file..")?;
+ }
+
+ // if let Some(rx_total_color) = &colours.rx_total_color {
+ // painter.colours.set_rx_total_colour(rx_total_color)?;
+ // }
+
+ // if let Some(tx_total_color) = &colours.tx_total_color {
+ // painter.colours.set_tx_total_colour(tx_total_color)?;
+ // }
+
+ if let Some(table_header_color) = &colours.table_header_color {
+ self.colours
+ .set_table_header_colour(table_header_color)
+ .context("Update 'table_header_color' in your config file..")?;
+ }
+
+ if let Some(scroll_entry_text_color) = &colours.selected_text_color {
+ self.colours
+ .set_scroll_entry_text_color(scroll_entry_text_color)
+ .context("Update 'selected_text_color' in your config file..")?;
+ }
+
+ if let Some(scroll_entry_bg_color) = &colours.selected_bg_color {
+ self.colours
+ .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.colours
+ .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.colours
+ .set_graph_colour(graph_color)
+ .context("Update 'graph_color' in your config file..")?;
+ }
+
+ if let Some(battery_colors) = &colours.battery_colors {
+ self.colours
+ .set_battery_colors(battery_colors)
+ .context("Update 'battery_colors' in your config file.")?;
+ }
}
+
+ Ok(())
}
/// Must be run once before drawing, but after setting colours.
/// This is to set some remaining styles and text.
- pub fn complete_painter_init(&mut self) {
+ fn complete_painter_init(&mut self) {
self.is_mac_os = cfg!(target_os = "macos");
let mut styled_help_spans = Vec::new();
@@ -191,6 +313,9 @@ impl Painter {
self.styled_help_text = styled_help_spans;
}
+ // FIXME: [CONFIG] write this, should call painter init and any changed colour functions...
+ pub fn update_painter_colours(&mut self) {}
+
pub fn draw_data<B: Backend>(
&mut self, terminal: &mut Terminal<B>, app_state: &mut app::App,
) -> error::Result<()> {
@@ -406,6 +531,13 @@ impl Painter {
),
_ => {}
}
+ } else if app_state.is_config_open {
+ let rect = Layout::default()
+ .margin(0)
+ .constraints([Constraint::Percentage(100)].as_ref())
+ .split(f.size())[0];
+
+ self.draw_config_screen(&mut f, app_state, rect)
} else if app_state.app_config_fields.use_basic_mode {
// Basic mode. This basically removes all graphs but otherwise
// the same info.