feat: add logger and config structure

This commit is contained in:
72-S committed 2025-01-30 13:57:23 +01:00
1 parent 15abd84501
commit d9c827b3ef
11 files changed
+906 -19

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
use config::{Config as ConfigLoader, ConfigError, File};
use dirs_next::config_dir;
use std::fs;
use std::path::PathBuf;
use obj::Config;
pub mod obj;
fn get_config_path() -> PathBuf {
let base_dir = config_dir().unwrap();
base_dir.join("mcl/config.toml")
}
pub fn ensure_config_exists(default_path: &str) -> PathBuf {
let config_path = get_config_path();
if !config_path.exists() {
if let Some(parent_dir) = config_path.parent() {
fs::create_dir_all(parent_dir).expect("Failed to create configuration directory");
}
fs::copy(default_path, &config_path).expect("Failed to copy default configuration file");
println!("Default configuration copied to '{}'", config_path.display());
}
config_path
}
pub fn load_config(config_path: &PathBuf) -> Result<Config, ConfigError> {
ConfigLoader::builder()
.add_source(File::from(config_path.clone()))
.build()?
.try_deserialize()
}
+28
View File
@@ -0,0 +1,28 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Variables {
pub debug: bool,
}
#[derive(Debug, Deserialize)]
pub struct Paths {
pub log_dir: String,
pub config_dir: String,
pub save_dir: String,
}
#[derive(Debug, Deserialize)]
pub struct Colors {
pub background: String,
pub foreground: String,
pub highlight: String,
pub focused: String,
}
#[derive(Debug, Deserialize)]
pub struct Config {
pub variables: Variables,
pub paths: Paths,
pub colors: Colors,
}