pub mod loader;
pub use loader::load_config;
use serde::{Deserialize, Serialize};
use crate::domain::format::{AngleMode, FormatSettings, Notation};
const DEFAULT_DECIMALS: usize = 3;
const DEFAULT_MAX_HISTORY: usize = 500;
pub const DEFAULT_ACCENT_COLOR: &str = "#82e38e";
pub const DEFAULT_FUNCTION_COLOR: &str = "#78c2b3";
pub const DEFAULT_CONSTANT_COLOR: &str = "#7c94ff";
pub const DEFAULT_OPERATOR_COLOR: &str = "#fe7057";
pub const DEFAULT_NUMBER_COLOR: &str = "#e5cb49";
pub const DEFAULT_VARIABLE_COLOR: &str = "#b27cde";
pub const DEFAULT_ANS_COLOR: &str = "#7dcfff";
pub const DEFAULT_COMMENT_COLOR: &str = "#67c1e5";
pub const DEFAULT_UNIT_COLOR: &str = "#ff79c6";
pub const DEFAULT_SETTINGS_BAR_BG: &str = "#252525";
pub const DEFAULT_HISTORY_ALT_BG: &str = "#1a1a1a";
pub const DEFAULT_HISTORY_SEPARATOR_COLOR: &str = "#3e3e3e";
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize,
)]
#[serde(rename_all = "lowercase")]
pub enum GlyphSet {
#[default]
Unicode,
Ascii,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Theme {
pub accent_color: String,
pub function_color: String,
pub constant_color: String,
pub operator_color: String,
pub number_color: String,
pub variable_color: String,
pub ans_color: String,
pub comment_color: String,
pub unit_color: String,
pub settings_bar_bg: String,
pub history_alt_bg: String,
pub history_separator_color: String,
}
impl Default for Theme {
fn default() -> Self {
Theme {
accent_color: DEFAULT_ACCENT_COLOR.to_string(),
function_color: DEFAULT_FUNCTION_COLOR.to_string(),
constant_color: DEFAULT_CONSTANT_COLOR.to_string(),
operator_color: DEFAULT_OPERATOR_COLOR.to_string(),
number_color: DEFAULT_NUMBER_COLOR.to_string(),
variable_color: DEFAULT_VARIABLE_COLOR.to_string(),
ans_color: DEFAULT_ANS_COLOR.to_string(),
comment_color: DEFAULT_COMMENT_COLOR.to_string(),
unit_color: DEFAULT_UNIT_COLOR.to_string(),
settings_bar_bg: DEFAULT_SETTINGS_BAR_BG.to_string(),
history_alt_bg: DEFAULT_HISTORY_ALT_BG.to_string(),
history_separator_color: DEFAULT_HISTORY_SEPARATOR_COLOR
.to_string(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Config {
pub notation: Notation,
pub decimals: usize,
pub angle_mode: AngleMode,
pub decimal_separator: char,
pub thousands_separator: String,
pub trim_trailing_zeros: bool,
pub max_history: usize,
pub glyphs: GlyphSet,
pub restore_last_settings: bool,
pub live_feedback: bool,
pub history_zebra: bool,
pub history_spacing: usize,
pub history_separator: bool,
pub input_max_lines: usize,
pub theme: Theme,
}
impl Default for Config {
fn default() -> Self {
Config {
notation: Notation::default(),
decimals: DEFAULT_DECIMALS,
angle_mode: AngleMode::default(),
decimal_separator: '.',
thousands_separator: " ".to_string(),
trim_trailing_zeros: true,
max_history: DEFAULT_MAX_HISTORY,
glyphs: GlyphSet::default(),
restore_last_settings: true,
live_feedback: true,
history_zebra: false,
history_spacing: 1,
history_separator: true,
input_max_lines: 5,
theme: Theme::default(),
}
}
}
impl Config {
pub fn format_settings(&self) -> FormatSettings {
FormatSettings {
notation: self.notation,
decimals: self.decimals,
angle_mode: self.angle_mode,
decimal_separator: self.decimal_separator,
thousands_separator: self.thousands_separator.clone(),
trim_trailing_zeros: self.trim_trailing_zeros,
}
}
}