From 019540a4f522d000c0172faeb096f1af35ad95db Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Mon, 25 Mar 2024 15:53:21 +0100 Subject: [PATCH 1/3] #447: added error message for incompatible fzf version --- src/finder/mod.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/finder/mod.rs b/src/finder/mod.rs index 9b4ccfd..bc745ff 100644 --- a/src/finder/mod.rs +++ b/src/finder/mod.rs @@ -3,12 +3,18 @@ use crate::prelude::*; use std::io::Write; use std::process::{self, Output}; use std::process::{Command, Stdio}; +use std::string::ToString; + pub mod structures; use clap::ValueEnum; pub use post::process; use structures::Opts; use structures::SuggestionType; +const MIN_FZF_VERSION_MAJOR: u32 = 0; +const MIN_FZF_VERSION_MINOR: u32 = 23; +const MIN_FZF_VERSION_PATCH: u32 = 1; + mod post; #[derive(Debug, Clone, Copy, Deserialize, ValueEnum)] @@ -47,6 +53,24 @@ fn parse(out: Output, opts: Opts) -> Result { } impl FinderChoice { + fn check_fzf_version() -> Option<(u32, u32, u32)> { + let output = Command::new("fzf") + .arg("--version") + .output() + .ok()? + .stdout; + let version_string = String::from_utf8(output).ok()?; + let version_parts: Vec<_> = version_string.split('.').collect(); + if version_parts.len() == 3 { + let major = version_parts[0].parse().ok()?; + let minor = version_parts[1].parse().ok()?; + let patch = version_parts[2].split_whitespace().next()?.parse().ok()?; + Some((major, minor, patch)) + } else { + None + } + } + pub fn call(&self, finder_opts: Opts, stdin_fn: F) -> Result<(String, R)> where F: Fn(&mut dyn Write) -> Result, @@ -56,6 +80,20 @@ impl FinderChoice { Self::Skim => "sk", }; + if let Self::Fzf = self { + if let Some((major, minor, patch)) = Self::check_fzf_version() { + if major == MIN_FZF_VERSION_MAJOR && minor < MIN_FZF_VERSION_MINOR && patch < MIN_FZF_VERSION_PATCH { + eprintln!("Warning: Fzf version {}.{} does not support the preview window layout used by navi.", major, minor); + eprintln!("Consider updating Fzf to a version >= {}.{}.{} or use a compatible layout.", + MIN_FZF_VERSION_MAJOR, + MIN_FZF_VERSION_MINOR, + MIN_FZF_VERSION_PATCH + ); + process::exit(1); + } + } + } + let mut command = Command::new(finder_str); let opts = finder_opts.clone(); From 5f3d0a44455ceea3b5339d0b6fcb5505021cde6a Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Mon, 25 Mar 2024 16:07:15 +0100 Subject: [PATCH 2/3] removed unused "use" --- src/finder/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/finder/mod.rs b/src/finder/mod.rs index bc745ff..2ece777 100644 --- a/src/finder/mod.rs +++ b/src/finder/mod.rs @@ -3,7 +3,6 @@ use crate::prelude::*; use std::io::Write; use std::process::{self, Output}; use std::process::{Command, Stdio}; -use std::string::ToString; pub mod structures; use clap::ValueEnum; From 4c65d780272c7954601c006fd23f63fe1f50a17c Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Mon, 25 Mar 2024 16:11:38 +0100 Subject: [PATCH 3/3] removed added blank line --- src/finder/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/finder/mod.rs b/src/finder/mod.rs index 2ece777..f19f2ca 100644 --- a/src/finder/mod.rs +++ b/src/finder/mod.rs @@ -3,7 +3,6 @@ use crate::prelude::*; use std::io::Write; use std::process::{self, Output}; use std::process::{Command, Stdio}; - pub mod structures; use clap::ValueEnum; pub use post::process;