use regex::Regex;
use serde::{Deserialize, Serialize};
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
convert::TryInto,
path::PathBuf,
str::FromStr,
time::Instant,
};
use crate::{
app::{
layout_manager::*,
widgets::{DiskWidgetState, ProcWidget, ProcWidgetMode, TempWidgetState},
*,
},
canvas::ColourScheme,
constants::*,
units::data_units::DataUnit,
utils::error::{self, BottomError},
};
use typed_builder::*;
use layout_options::*;
pub mod layout_options;
use anyhow::{Context, Result};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Config {
pub flags: Option<ConfigFlags>,
pub colors: Option<ConfigColours>,
pub row: Option<Vec<Row>>,
pub disk_filter: Option<IgnoreList>,
pub mount_filter: Option<IgnoreList>,
pub temp_filter: Option<IgnoreList>,
pub net_filter: Option<IgnoreList>,
}
impl Config {
pub fn get_config_as_bytes(&self) -> anyhow::Result<Vec<u8>> {
let config_string: Vec<Cow<'_, str>> = vec![
// Top level
CONFIG_TOP_HEAD.into(),
toml::to_string_pretty(self)?.into(),
];
Ok(config_string.concat().as_bytes().to_vec())
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, TypedBuilder)]
pub struct ConfigFlags {
#[builder(default, setter(strip_option))]
pub hide_avg_cpu: Option<bool>,
#[builder(default, setter(strip_option))]
pub dot_marker: Option<bool>,
#[builder(default, setter(strip_option))]
pub temperature_type: Option<String>,
#[builder(default, setter(strip_option))]
pub rate: Option<u64>,
#[builder(default, setter(strip_option))]
pub left_legend: Option<bool>,
#[builder(default, setter(strip_option))]
pub current_usage: Option<bool>,
#[builder(default, setter(strip_option))]
pub group_processes: Option<bool>,
#[builder(default, setter(strip_option))]
pub case_sensitive: Option<bool>,
#[builder(default, setter(strip_option))]
pub whole_word: Option<bool>,
#[builder(default, setter(strip_option))]
pub regex: Option<bool>,
#[builder(default, setter(strip_option))]
pub basic: Option<bool>,
#[builder(default, setter(strip_option))]
pub default_time_value: Option<u64>,
#[builder(default, setter(strip_option))]
pub time_delta: Option<u64>,
#[builder(default, setter(strip_option))]
pub autohide_time: Option<bool>,
#[builder(default, setter(strip_option))]
pub hide_time: Option<bool>,
#[builder(default, setter(strip_option))]
pub default_widget_type: Option<String>,
#[builder(default, setter(strip_option))]
pub default_widget_count: Option<u64>,
#[builder(default, setter(strip_option))]
pub use_old_network_legend: Option<bool>,
#[builder(default, setter(strip_option))]
pub hide_table_gap: Option<bool>,
#[builder(default, setter(strip_option))]
pub battery: Option<bool>,
#[builder(default, setter(strip_option))]
pub disable_click: Option<bool>,
#[builder(default, setter(strip_option))]
pub no_write: Option<bool>,
// For built-in colour palettes.
#[builder(default, setter(strip_option))]
pub color: Option<String>,
// This is a huge hack to enable hashmap functionality WITHOUT being able to serializing the field.
// Basically, keep a hashmap in the struct, and convert to a vector every time.
#[builder(default, setter(strip_option))]
#[serde(skip)]
pub search_case_enabled_widgets_map: Option<HashMap<u64, bool>>,
#[builder(default, setter(strip_option))]
pub search_case_enabled_widgets: Option<Vec<WidgetIdEnabled>>,
#[builder(default, setter(strip_option))]
#[serde(skip)]
pub search_whole_word_enabled_widgets_map: Option<HashMap<u64, bool>>,
#[builder(default, setter(strip_option))]
pub search_whole_word_enabled_widgets: Option