started parsing of config file

This commit is contained in:
2024-12-09 22:53:13 +01:00
parent 61e3ded722
commit c27089124e
3 changed files with 20 additions and 7 deletions
+1
View File
@@ -6,3 +6,4 @@ edition = "2021"
[dependencies]
clap = { version = "4.5.0", features = ["derive"] }
sysinfo = "0.32.0"
toml = "0.8.19"
+17 -3
View File
@@ -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::<Table>() {
Ok(value) => value,
Err(error) => return Err(Error::other(error.to_string())),
};
Ok(())
}
}
+2 -4
View File
@@ -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(())
}