use std::{
borrow::Cow,
collections::{HashMap, HashSet},
convert::TryInto,
str::FromStr,
time::{Duration, Instant},
};
use clap::ArgMatches;
use layout_options::*;
use regex::Regex;
use serde::{Deserialize, Serialize};
#[cfg(feature = "battery")]
use starship_battery::Manager;
use typed_builder::*;
use crate::{
app::{layout_manager::*, *},
canvas::{canvas_styling::CanvasColours, ColourScheme},
constants::*,
units::data_units::DataUnit,
utils::error::{self, BottomError},
widgets::{
BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState,
ProcWidgetMode, ProcWidgetState, TempWidgetState,
},
};
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 {
pub hide_avg_cpu: Option<bool>,
pub dot_marker: Option<bool>,
pub temperature_type: Option<String>,
pub rate: Option<u64>,
pub left_legend: Option<bool>,
pub current_usage: Option<bool>,
pub unnormalized_cpu: Option<bool>,
pub group_processes: Option<bool>,
pub case_sensitive: Option<bool>,
pub whole_word: Option<bool>,
pub regex: Option<bool>,
pub basic: Option<bool>,
pub default_time_value: Option<u64>,
pub time_delta: Option<u64>,
pub autohide_time: Option<bool>,
pub hide_time: Option<bool>,
pub default_widget_type: Option<String>,
pub default_widget_count: Option<u64>,
pub expanded_on_startup: Option<bool>,
pub use_old_network_legend: Option<bool>,
pub hide_table_gap: Option<bool>,
pub battery: Option<bool>,
pub disable_click: Option<bool>,
pub no_write: Option<bool>,
// For built-in colour palettes.
pub color: Option<String>,
pub mem_as_value: Option<bool>,
pub tree: Option<bool>,
show_table_scroll_position: Option<bool>,
pub process_command: Option<bool>,
pub disable_advanced_kill: Option<bool>,
pub network_use_bytes: Option<bool>,
pub network_use_log: Option<bool>,
pub network_use_binary_prefix: Option<bool>,
pub enable_gpu_memory: Option<bool>,
#[serde(with = "humantime_serde")]
#[serde(default)]
pub retention: Option<Duration>,
}
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
pub struct WidgetIdEnabled {
id: u64,
enabled: bool,
}
impl WidgetIdEnabled {
pub fn create_from_hashmap(hashmap: &HashMap<u64, bool>) -> Vec<WidgetIdEnabled> {
hashmap
.iter()
.map(|(id