diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-10-17 22:16:40 +0200 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-10-17 22:16:40 +0200 |
commit | 7453c1c0dc580c1054a8dcac5183fc6e58f3f482 (patch) | |
tree | 0c22ee6aafe852e58b206901a38b4ade8cef83d7 /src/marks.rs | |
parent | 3c05da468c664b0f68d5ebdca2e17f23b4b92bd5 (diff) |
basic steps for marks implementation; no action yet
Diffstat (limited to 'src/marks.rs')
-rw-r--r-- | src/marks.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/marks.rs b/src/marks.rs index 97cb68a..1c7abf0 100644 --- a/src/marks.rs +++ b/src/marks.rs @@ -4,12 +4,19 @@ use std::fs::OpenOptions; use std::io::{self, BufRead, BufWriter, Error, ErrorKind, Write}; use std::path::{Path, PathBuf}; +static MARKS_FILEPATH: &str = "~/.config/fm/marks.cfg"; + pub struct Marks { save_path: PathBuf, marks: HashMap<char, PathBuf>, } impl Marks { + pub fn read_from_config_file() -> Self { + Self::read_from_file(PathBuf::from( + std::fs::canonicalize(MARKS_FILEPATH).unwrap_or(PathBuf::new()), + )) + } pub fn read_from_file(save_path: PathBuf) -> Self { let mut marks = HashMap::new(); if let Ok(lines) = read_lines(&save_path) { @@ -42,6 +49,8 @@ impl Marks { } fn save_marks(&self) { + let _ = std::fs::File::create(MARKS_FILEPATH); + let file = OpenOptions::new() .write(true) .open(self.save_path.clone()) @@ -67,6 +76,7 @@ impl Marks { s.push(*ch); s.push(':'); s.push_str(&path.clone().into_os_string().into_string().unwrap()); + s.push('\n'); } s } |