init, basic glogg clone

This commit is contained in:
2025-12-02 18:30:12 +01:00
commit a53ced9160
26 changed files with 6512 additions and 0 deletions

39
src/config.rs Normal file
View File

@@ -0,0 +1,39 @@
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use crate::types::HighlightRule;
#[derive(Serialize, Deserialize, Default)]
pub struct AppConfig {
pub search_history: Vec<String>,
pub case_sensitive: bool,
pub use_regex: bool,
pub last_search_query: String,
#[serde(default)]
pub highlight_rules: Vec<HighlightRule>,
}
impl AppConfig {
fn config_path() -> PathBuf {
let exe_path = std::env::current_exe().unwrap_or_else(|_| PathBuf::from("."));
let exe_dir = exe_path.parent().unwrap_or_else(|| std::path::Path::new("."));
exe_dir.join("rlogg_config.json")
}
pub fn load() -> Self {
let path = Self::config_path();
if let Ok(contents) = fs::read_to_string(&path) {
serde_json::from_str(&contents).unwrap_or_default()
} else {
Self::default()
}
}
pub fn save(&self) {
let path = Self::config_path();
if let Ok(json) = serde_json::to_string_pretty(self) {
let _ = fs::write(&path, json);
}
}
}