summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2022-10-17 22:16:40 +0200
committerqkzk <qu3nt1n@gmail.com>2022-10-17 22:16:40 +0200
commit7453c1c0dc580c1054a8dcac5183fc6e58f3f482 (patch)
tree0c22ee6aafe852e58b206901a38b4ade8cef83d7
parent3c05da468c664b0f68d5ebdca2e17f23b4b92bd5 (diff)
basic steps for marks implementation; no action yet
-rw-r--r--config.yaml2
-rw-r--r--src/config.rs10
-rw-r--r--src/event_char.rs4
-rw-r--r--src/marks.rs10
-rw-r--r--src/mode.rs6
-rw-r--r--src/tabs.rs26
6 files changed, 58 insertions, 0 deletions
diff --git a/config.yaml b/config.yaml
index 70941d27..db87b012 100644
--- a/config.yaml
+++ b/config.yaml
@@ -40,3 +40,5 @@ keybindings:
symlink: S
preview: P
history: H
+ marks_new: M
+ marks_jump: "'"
diff --git a/src/config.rs b/src/config.rs
index d343c915..14972b3c 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -202,6 +202,8 @@ pub struct Keybindings {
pub shortcut: char,
/// Bulkrename
pub bulkrename: char,
+ pub marks_new: char,
+ pub marks_jump: char,
}
impl Keybindings {
@@ -292,6 +294,12 @@ impl Keybindings {
if let Some(bulkrename) = yaml["bulkrename"].as_str().map(|s| s.to_string()) {
self.bulkrename = bulkrename.chars().next().unwrap_or('B');
}
+ if let Some(marks_new) = yaml["marks_new"].as_str().map(|s| s.to_string()) {
+ self.marks_new = marks_new.chars().next().unwrap_or('M');
+ }
+ if let Some(marks_jump) = yaml["marks_jump"].as_str().map(|s| s.to_string()) {
+ self.marks_jump = marks_jump.chars().next().unwrap_or('\'');
+ }
}
/// Returns a new `Keybindings` instance with hardcoded values.
@@ -325,6 +333,8 @@ impl Keybindings {
history: 'H',
shortcut: 'G',
bulkrename: 'B',
+ marks_new: 'M',
+ marks_jump: '\'',
}
}
}
diff --git a/src/event_char.rs b/src/event_char.rs
index 88d90366..b3b3dfd6 100644
--- a/src/event_char.rs
+++ b/src/event_char.rs
@@ -29,6 +29,8 @@ pub enum EventChar {
Preview,
Shortcut,
Bulkrename,
+ MarksNew,
+ MarksJump,
}
impl EventChar {
@@ -63,6 +65,8 @@ impl EventChar {
EventChar::Preview => current_status.event_preview(),
EventChar::Shortcut => current_status.event_shortcut(),
EventChar::Bulkrename => tabs.event_bulkrename(),
+ EventChar::MarksNew => tabs.event_marks_new(),
+ EventChar::MarksJump => tabs.event_marks_jump(),
}
}
}
diff --git a/src/marks.rs b/src/marks.rs
index 97cb68a6..1c7abf01 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
}
diff --git a/src/mode.rs b/src/mode.rs
index 89bcb039..ae84cd9d 100644
--- a/src/mode.rs
+++ b/src/mode.rs
@@ -37,6 +37,10 @@ pub enum Mode {
History,
/// Display predefined shortcuts
Shortcut,
+ /// Jump to a saved mark
+ MarksJump,
+ /// Save a new mark, edit one
+ MarksNew,
}
impl fmt::Debug for Mode {
@@ -58,6 +62,8 @@ impl fmt::Debug for Mode {
Mode::Sort => write!(f, "(N)ame (D)ate (S)ize (E)xt (R)ev :"),
Mode::Preview => write!(f, "Preview : "),
Mode::Shortcut => write!(f, "Shortcut :"),
+ Mode::MarksJump => write!(f, "Marks jump:"),
+ Mode::MarksNew => write!(f, "Marks save:"),
}
}
}
diff --git a/src/tabs.rs b/src/tabs.rs
index 2a457c2f..f58111fa 100644
--- a/src/tabs.rs
+++ b/src/tabs.rs
@@ -11,6 +11,7 @@ use crate::bulkrename::Bulkrename;
use crate::config::Config;
use crate::fileinfo::PathContent;
use crate::last_edition::LastEdition;
+use crate::marks::Marks;
use crate::mode::Mode;
use crate::status::Status;
@@ -23,6 +24,8 @@ pub struct Tabs {
pub flagged: HashSet<PathBuf>,
/// Index in the jump list
pub jump_index: usize,
+ /// Marks allows you to jump to a save mark
+ pub marks: Marks,
}
impl Tabs {
@@ -34,6 +37,7 @@ impl Tabs {
index: 0,
flagged: HashSet::new(),
jump_index: 0,
+ marks: Marks::read_from_config_file(),
}
}
@@ -204,6 +208,28 @@ impl Tabs {
}
}
+ pub fn event_marks_new(&mut self) {
+ // display the current path
+
+ // display the marks
+
+ // read a char
+
+ // save
+ }
+
+ pub fn event_marks_jump(&mut self) {
+ // display the marks
+
+ // read a char
+
+ // parse char
+ }
+
+ pub fn exec_marks_new(&mut self) {}
+
+ pub fn exec_marks_jump(&mut self) {}
+
/// Creates a symlink of every flagged file to the current directory.
pub fn event_symlink(&mut self) {
self.flagged.iter().for_each(|oldpath| {