diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-09-27 16:01:01 +0200 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-09-27 16:01:01 +0200 |
commit | 44263aa67d23902b924c5456924f1d75d5b01031 (patch) | |
tree | 52edf7fa1eb2832fcab9b858a6f945855ee0d7ab /src | |
parent | b3baa1b9c7d89d31b5f7609f8b90cbf295f5c7d4 (diff) |
preview of diff files & iso content require diff & isoinfo installed
Diffstat (limited to 'src')
-rw-r--r-- | src/constant_strings_paths.rs | 4 | ||||
-rw-r--r-- | src/event_exec.rs | 5 | ||||
-rw-r--r-- | src/preview.rs | 16 |
3 files changed, 19 insertions, 6 deletions
diff --git a/src/constant_strings_paths.rs b/src/constant_strings_paths.rs index 6cdb8bd..d67a90d 100644 --- a/src/constant_strings_paths.rs +++ b/src/constant_strings_paths.rs @@ -164,3 +164,7 @@ pub const UEBERZUG: &str = "ueberzug"; pub const JUPYTER: &str = "jupyter"; /// pandoc. used to preview .doc & .odb documents pub const PANDOC: &str = "pandoc"; +/// diff. used to preview diff between files +pub const DIFF: &str = "diff"; +/// isoinfo. used to preview iso file content +pub const ISOINFO: &str = "isoinfo"; diff --git a/src/event_exec.rs b/src/event_exec.rs index 815aa3d..3a86a2b 100644 --- a/src/event_exec.rs +++ b/src/event_exec.rs @@ -11,6 +11,7 @@ use which::which; use crate::action_map::ActionMap; use crate::completion::InputCompleted; use crate::config::Colors; +use crate::constant_strings_paths::DIFF; use crate::constant_strings_paths::MEDIAINFO; use crate::constant_strings_paths::NITROGEN; use crate::constant_strings_paths::SSHFS_EXECUTABLE; @@ -828,6 +829,10 @@ impl EventAction { /// Display a diff between the first 2 flagged files or dir. pub fn diff(status: &mut Status) -> Result<()> { + if !is_program_in_path(DIFF) { + write_log_line(format!("{DIFF} isn't installed")); + return Ok(()); + } if status.flagged.len() < 2 { return Ok(()); }; diff --git a/src/preview.rs b/src/preview.rs index 8b24579..bd6ff21 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -19,7 +19,9 @@ use tuikit::attr::{Attr, Color}; use users::UsersCache; use crate::config::Colors; -use crate::constant_strings_paths::{JUPYTER, MEDIAINFO, PANDOC, THUMBNAIL_PATH, UEBERZUG}; +use crate::constant_strings_paths::{ + DIFF, ISOINFO, JUPYTER, MEDIAINFO, PANDOC, THUMBNAIL_PATH, UEBERZUG, +}; use crate::content_window::ContentWindow; use crate::decompress::list_files_zip; use crate::fileinfo::{FileInfo, FileKind}; @@ -97,7 +99,9 @@ impl Preview { e if is_ext_svg(e) && is_program_in_path(UEBERZUG) => { Ok(Self::Ueberzug(Ueberzug::svg_thumbnail(&file_info.path)?)) } - e if is_ext_iso(e) => Ok(Self::Iso(Iso::new(&file_info.path)?)), + e if is_ext_iso(e) && is_program_in_path(ISOINFO) => { + Ok(Self::Iso(Iso::new(&file_info.path)?)) + } e if is_ext_notebook(e) && is_program_in_path(JUPYTER) => { Ok(Self::notebook(&file_info.path) .context("Preview: Couldn't parse notebook")?) @@ -886,11 +890,11 @@ pub struct Diff { impl Diff { pub fn new(first_path: &str, second_path: &str) -> Result<Self> { let content: Vec<String> = - execute_and_capture_output_without_check("diff", &[first_path, second_path])? + execute_and_capture_output_without_check(DIFF, &[first_path, second_path])? .lines() .map(|s| s.to_owned()) .collect(); - info!("diff:\n{content:?}"); + info!("{DIFF}:\n{content:?}"); Ok(Self { length: content.len(), @@ -912,11 +916,11 @@ impl Iso { fn new(path: &Path) -> Result<Self> { let path = path.to_str().context("couldn't parse the path")?; let content: Vec<String> = - execute_and_capture_output_without_check("isoinfo", &["-l", "-i", path])? + execute_and_capture_output_without_check(ISOINFO, &["-l", "-i", path])? .lines() .map(|s| s.to_owned()) .collect(); - info!("isofino:\n{content:?}"); + info!("{ISOINFO}:\n{content:?}"); Ok(Self { length: content.len(), |