diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-10-14 14:01:15 +0200 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-10-14 14:01:15 +0200 |
commit | 48b903217ee17a0cb59da3f316cadd6b941861cf (patch) | |
tree | 9ab22e58aa08652df3afa39b4b65bd2d82425edc /src/opener.rs | |
parent | 5098df7451f7dd186d1965f475483a75aac7b79c (diff) |
refactor opener and ExtensionKind
Diffstat (limited to 'src/opener.rs')
-rw-r--r-- | src/opener.rs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/opener.rs b/src/opener.rs index fe02fba..a81d5d4 100644 --- a/src/opener.rs +++ b/src/opener.rs @@ -51,8 +51,8 @@ pub enum ExtensionKind { // TODO: move those associations to a config file impl ExtensionKind { - fn parse(ext: &str) -> Self { - match ext.to_lowercase().as_str() { + fn matcher(ext: &str) -> Self { + match ext { "avif" | "bmp" | "gif" | "png" | "jpg" | "jpeg" | "pgm" | "ppm" | "webp" | "tiff" => { Self::Bitmap } @@ -126,7 +126,6 @@ impl OpenerAssociation { ExtensionKind::Text, OpenerInfo::external(DEFAULT_TEXT_OPENER), ), - (ExtensionKind::Default, OpenerInfo::external(DEFAULT_OPENER)), ( ExtensionKind::Vectorial, OpenerInfo::external(DEFAULT_VECTORIAL_OPENER), @@ -138,23 +137,24 @@ impl OpenerAssociation { ( ExtensionKind::Internal(InternalVariant::DecompressZip), OpenerInfo::internal(ExtensionKind::Internal(InternalVariant::DecompressZip)) - .unwrap(), + .unwrap_or_default(), ), ( ExtensionKind::Internal(InternalVariant::DecompressGz), OpenerInfo::internal(ExtensionKind::Internal(InternalVariant::DecompressGz)) - .unwrap(), + .unwrap_or_default(), ), ( ExtensionKind::Internal(InternalVariant::DecompressXz), OpenerInfo::internal(ExtensionKind::Internal(InternalVariant::DecompressXz)) - .unwrap(), + .unwrap_or_default(), ), ( ExtensionKind::Internal(InternalVariant::NotSupported), OpenerInfo::internal(ExtensionKind::Internal(InternalVariant::NotSupported)) - .unwrap(), + .unwrap_or_default(), ), + (ExtensionKind::Default, OpenerInfo::external(DEFAULT_OPENER)), ]), } } @@ -189,7 +189,8 @@ macro_rules! open_file_with { impl OpenerAssociation { fn opener_info(&self, ext: &str) -> Option<&OpenerInfo> { - self.association.get(&ExtensionKind::parse(ext)) + self.association + .get(&ExtensionKind::matcher(&ext.to_lowercase())) } fn update_from_file(&mut self, yaml: &serde_yaml::value::Value) { @@ -237,6 +238,16 @@ pub struct OpenerInfo { use_term: bool, } +impl Default for OpenerInfo { + fn default() -> Self { + Self { + external_program: Some("/usr/bin/xdg-open".to_owned()), + internal_variant: None, + use_term: false, + } + } +} + impl OpenerInfo { fn external(opener_pair: (&str, bool)) -> Self { let opener = opener_pair.0; |