summaryrefslogtreecommitdiffstats
path: root/src/opener.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2022-10-16 01:04:26 +0200
committerqkzk <qu3nt1n@gmail.com>2022-10-16 01:04:26 +0200
commit4db7b345d8d1439ab61d6c75938315b39b47b4d3 (patch)
tree08886251239ac3e8bd3b3414122bae3c81d9b72d /src/opener.rs
parent6e5f19310f42f2ac88f0def2779f79e9dd160943 (diff)
basic step, can't open editor yet. Need a Mode
Diffstat (limited to 'src/opener.rs')
-rw-r--r--src/opener.rs38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/opener.rs b/src/opener.rs
index ad661bb..c5dcaf1 100644
--- a/src/opener.rs
+++ b/src/opener.rs
@@ -5,7 +5,7 @@ use std::process::Command;
use serde_yaml;
#[derive(Clone, Hash, Eq, PartialEq)]
-enum ExtensionKind {
+pub enum ExtensionKind {
Audio,
Bitmap,
Office,
@@ -112,7 +112,7 @@ impl ExtensionKind {
}
#[derive(Clone)]
-struct OpenerAssociation {
+pub struct OpenerAssociation {
association: HashMap<ExtensionKind, OpenerInfo>,
}
@@ -180,7 +180,7 @@ impl OpenerAssociation {
}
#[derive(Clone)]
-struct OpenerInfo {
+pub struct OpenerInfo {
opener: String,
use_term: bool,
}
@@ -210,7 +210,7 @@ impl OpenerInfo {
#[derive(Clone)]
pub struct Opener {
terminal: String,
- opener_association: OpenerAssociation,
+ pub opener_association: OpenerAssociation,
}
impl Opener {
@@ -229,21 +229,25 @@ impl Opener {
if let Some(extension_os_str) = filepath.extension() {
let extension = extension_os_str.to_str().unwrap();
if let Some(open_info) = self.opener_association.opener_info(extension) {
- if open_info.use_term {
- self.open_terminal(
- open_info.opener.clone(),
- filepath.to_str().unwrap().to_owned(),
- )
- } else {
- self.open_directly(
- open_info.opener.clone(),
- filepath.to_str().unwrap().to_owned(),
- )
- }
+ self.open_with(open_info, filepath)
}
}
}
+ pub fn open_with(&self, open_info: &OpenerInfo, filepath: std::path::PathBuf) {
+ if open_info.use_term {
+ self.open_terminal(
+ open_info.opener.clone(),
+ filepath.to_str().unwrap().to_owned(),
+ )
+ } else {
+ self.open_directly(
+ open_info.opener.clone(),
+ filepath.to_str().unwrap().to_owned(),
+ )
+ }
+ }
+
pub fn update_from_file(&mut self, yaml: &serde_yaml::value::Value) {
self.opener_association.update_from_file(yaml)
}
@@ -256,6 +260,10 @@ impl Opener {
fn open_terminal(&self, executable: String, filepath: String) {
execute_in_child(&self.terminal, &vec!["-e", &executable, &filepath]);
}
+
+ pub fn get(&self, kind: ExtensionKind) -> Option<&OpenerInfo> {
+ self.opener_association.association.get(&kind)
+ }
}
/// Execute the command in a fork.