diff --git a/Cargo.toml b/Cargo.toml index 9178994..e778eb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" [dependencies] clap = { version = "4.5.0", features = ["derive"] } sysinfo = "0.32.0" +toml = "0.8.19" diff --git a/src/config.rs b/src/config.rs index 250ecfc..0132125 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,12 +1,12 @@ //! handle the config file and bookmarks stored //! in said config file -use std::env::var; -use std::fs; -use std::fs::File; use std::io::{Error, Result}; use std::path::PathBuf; +use std::env::var; +use std::fs; use std::str::FromStr; +use toml::{from_str, Table}; use crate::{RESET_SEQ, STYLES}; @@ -20,6 +20,7 @@ pub struct Config { #[derive(Debug, Clone)] pub struct Settings { pub general: GeneralSettings, + pub format: FormatSettings, pub styles: StyleSettings, } @@ -63,6 +64,10 @@ impl Config { show_stack_on_pop: false, show_stack_on_bookmark: false, }, + format: FormatSettings { + bookmarks_separator: " - ".to_owned(), + stack_separator: " - ".to_owned(), + }, styles: StyleSettings { stack_number: "".to_owned(), stack_separator: "".to_owned(), @@ -92,6 +97,15 @@ impl Config { /// reads and parses the configuration file fn build_config(&mut self) -> Result<()> { + let config_file = match fs::read_to_string(&self.conf_dir) { + Ok(value) => value, + Err(error) => return Err(error), + }; + let conf_table = match config_file.parse::() { + Ok(value) => value, + Err(error) => return Err(Error::other(error.to_string())), + }; + Ok(()) } } diff --git a/src/stack.rs b/src/stack.rs index 889581c..9bb9723 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -39,12 +39,10 @@ impl Stack { } /// clear stack by deleting the associated stack file - pub fn clear_stack(&mut self, config: &Config) -> Result<()> { + pub fn clear_stack(&mut self, _config: &Config) -> Result<()> { fs::remove_file(self.path.clone())?; print!( - "echo '{}stack cleared successfully.{}'", - "", - "" // TODO implement styling + "echo stack cleared successfully.'" ); Ok(()) }