diff options
author | quentin konieczko <konieczko@gmail.com> | 2022-10-14 13:38:04 +0200 |
---|---|---|
committer | quentin konieczko <konieczko@gmail.com> | 2022-10-14 13:38:04 +0200 |
commit | cb0830931782ef047f265c502723511a828a804d (patch) | |
tree | 0a23e8fd1bbe9a97d1dac3a0c879f106078b8cf5 /src/opener.rs | |
parent | 129b33d23d01e5f2c33c274417c552d2d3daead8 (diff) |
better structs
Diffstat (limited to 'src/opener.rs')
-rw-r--r-- | src/opener.rs | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/opener.rs b/src/opener.rs index f58aac6..5f13aa7 100644 --- a/src/opener.rs +++ b/src/opener.rs @@ -2,36 +2,58 @@ use std::collections::HashMap; use std::process::Command; #[derive(Clone)] -struct OpenConfig { +struct OpenerAssociation { + config: HashMap<String, OpenerInfo>, +} + +impl OpenerAssociation { + pub fn new() -> Self { + let config = Self::hard_coded(); + Self { config } + } + + fn hard_coded() -> HashMap<String, OpenerInfo> { + let mut association = HashMap::new(); + association.insert("md".to_owned(), OpenerInfo::new("nvim".to_owned(), true)); + association.insert( + "png".to_owned(), + OpenerInfo::new("viewnior".to_owned(), false), + ); + association + } + + fn update_from_file(filepath: std::path::PathBuf) {} +} + +#[derive(Clone)] +struct OpenerInfo { opener: String, use_term: bool, } -impl OpenConfig { +impl OpenerInfo { pub fn new(opener: String, use_term: bool) -> Self { - OpenConfig { opener, use_term } + Self { opener, use_term } } } #[derive(Clone)] pub struct Opener { terminal: String, - association: HashMap<String, OpenConfig>, + openers: OpenerAssociation, } impl Opener { pub fn new(terminal: String) -> Self { - let mut association = HashMap::new(); - association.insert("md".to_owned(), OpenConfig::new("nvim".to_owned(), true)); Self { terminal, - association, + openers: OpenerAssociation::new(), } } pub fn open(&self, filepath: std::path::PathBuf) { let extension = filepath.extension().unwrap().to_str().unwrap(); - if let Some(open_config) = self.association.get(extension) { + if let Some(open_config) = self.openers.config.get(extension) { if open_config.use_term { self.open_terminal( open_config.opener.clone(), |