use std::collections::HashMap;
use owo_colors::Style;
use crate::components::formater::{FormaterCompile, FormaterCompilerSignature, FormaterParamBuilder, FormaterParamBuilderSignature};
use crate::components::level::Level;
#[cfg(feature = "hconfig")]
use Hconfig::tinyjson::JsonValue;
pub struct CommandLineConfig
{
pub colors: HashMap<Level,Style>,
pub lineReturn: String,
pub lineFormat: String,
pub formaterParamBuilder: FormaterParamBuilderSignature,
pub formaterCompiler: FormaterCompilerSignature
}
impl Default for CommandLineConfig
{
fn default() -> Self {
let mut colors = HashMap::new();
colors.insert(Level::DEBUG, Style::new());
colors.insert(Level::NOTICE, Style::new().green());
colors.insert(Level::NOTICEDERR, Style::new().bright_green());
colors.insert(Level::WARNING, Style::new().yellow());
colors.insert(Level::DEBUGERR, Style::new().on_bright_red());
colors.insert(Level::ERROR, Style::new().on_red().black());
colors.insert(Level::FATAL, Style::new().on_purple().black());
return CommandLineConfig{
colors,
lineReturn: " | ".to_string(),
lineFormat: "{time} {lvl} ({thread:>, }{context:>, }{file}:l{line}) : {msg}".to_string(),
formaterParamBuilder: FormaterParamBuilder,
formaterCompiler: FormaterCompile,
};
}
}
#[cfg(feature = "hconfig")]
impl CommandLineConfig
{
pub fn create_from_hconfig(configs: &mut JsonValue) -> Self
{
use crate::modules::utils_hconfig::setConfig_String;
let mut newConfig = Self::default();
let JsonValue::Object(config) = configs else { return newConfig };
setConfig_String(config,"lineReturn",&mut newConfig.lineReturn,|_|true);
setConfig_String(config,"lineFormat",&mut newConfig.lineFormat,|a|{
!a.contains("{color}")
});
newConfig
}
}