mirror of
https://github.com/denisidoro/navi
synced 2024-11-23 20:13:05 +00:00
Merge pull request #888 from tolik518/incompatible-fzf-version
Added error message for incompatible fzf version
This commit is contained in:
commit
d713d501a0
1 changed files with 36 additions and 0 deletions
|
@ -9,6 +9,10 @@ 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 +51,24 @@ fn parse(out: Output, opts: Opts) -> Result<String> {
|
|||
}
|
||||
|
||||
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<F, R>(&self, finder_opts: Opts, stdin_fn: F) -> Result<(String, R)>
|
||||
where
|
||||
F: Fn(&mut dyn Write) -> Result<R>,
|
||||
|
@ -56,6 +78,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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue