summaryrefslogtreecommitdiffstats
path: root/src/marks.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2022-10-19 21:57:08 +0200
committerqkzk <qu3nt1n@gmail.com>2022-10-19 21:57:08 +0200
commite3254ce17eb3bcefe92dee52029cde62ebc9cb54 (patch)
treecea2e558e429770ed82cfaf62f571ed6638b64e8 /src/marks.rs
parent8556b340eb213171f9ce4e5f37c3a2d726223660 (diff)
display marks correctly
Diffstat (limited to 'src/marks.rs')
-rw-r--r--src/marks.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/marks.rs b/src/marks.rs
index 4d78a4b..09a0501 100644
--- a/src/marks.rs
+++ b/src/marks.rs
@@ -13,12 +13,11 @@ pub struct Marks {
impl Marks {
pub fn read_from_config_file() -> Self {
- Self::read_from_file(PathBuf::from(
- std::fs::canonicalize(MARKS_FILEPATH).unwrap_or(PathBuf::new()),
- ))
+ let path = PathBuf::from(shellexpand::tilde(&MARKS_FILEPATH).to_string());
+ Self::read_from_file(path)
}
- pub fn read_from_file(save_path: PathBuf) -> Self {
+ fn read_from_file(save_path: PathBuf) -> Self {
let mut marks = HashMap::new();
if let Ok(lines) = read_lines(&save_path) {
for line in lines {
@@ -54,8 +53,10 @@ impl Marks {
}
fn save_marks(&self) {
- eprintln!("save path {:?}", &self.save_path);
- let _ = std::fs::File::create(&self.save_path);
+ if !self.save_path.exists() {
+ let _ = std::fs::File::create(&self.save_path);
+ eprintln!("Created a file for marks in {:?}", &self.save_path);
+ }
let file = OpenOptions::new()
.write(true)
@@ -64,18 +65,17 @@ impl Marks {
let mut buf = BufWriter::new(file);
for (ch, path) in self.marks.iter() {
- let _ = write!(
- buf,
- "{}:{}",
- ch,
- path.clone()
- .into_os_string()
- .into_string()
- .unwrap_or("".to_owned())
- );
+ let _ = write!(buf, "{}:{}", ch, Self::path_as_string(path));
}
}
+ fn path_as_string(path: &PathBuf) -> String {
+ path.clone()
+ .into_os_string()
+ .into_string()
+ .unwrap_or("".to_owned())
+ }
+
pub fn as_strings(&self) -> Vec<String> {
self.marks
.iter()
@@ -86,7 +86,7 @@ impl Marks {
fn format_mark(ch: &char, path: &PathBuf) -> String {
let mut s = "".to_owned();
s.push(*ch);
- s.push(':');
+ s.push_str(" ");
s.push_str(&path.clone().into_os_string().into_string().unwrap());
s.push('\n');
s