From 7d92b48ff0431f3a84c06f0c1229be87f6c6e2f7 Mon Sep 17 00:00:00 2001 From: o2sh Date: Sat, 21 Nov 2020 15:00:13 +0100 Subject: [PATCH] fix image backend detection --- src/onefetch/image_backends/kitty.rs | 5 ----- src/onefetch/image_backends/mod.rs | 17 ++++++++--------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/onefetch/image_backends/kitty.rs b/src/onefetch/image_backends/kitty.rs index 775e2131f..748d25783 100644 --- a/src/onefetch/image_backends/kitty.rs +++ b/src/onefetch/image_backends/kitty.rs @@ -5,7 +5,6 @@ use { c_void, ioctl, poll, pollfd, read, tcgetattr, tcsetattr, termios, winsize, ECHO, ICANON, POLLIN, STDIN_FILENO, STDOUT_FILENO, TCSANOW, TIOCGWINSZ, }, - std::env, std::io::{stdout, Write}, std::time::Instant, }; @@ -18,10 +17,6 @@ impl KittyBackend { } pub fn supported() -> bool { - if !env::var("KITTY_WINDOW_ID").unwrap_or_else(|_| "".to_string()).is_empty() { - return true; - } - // save terminal attributes and disable canonical input processing mode let old_attributes = unsafe { let mut old_attributes: termios = std::mem::zeroed(); diff --git a/src/onefetch/image_backends/mod.rs b/src/onefetch/image_backends/mod.rs index fcc6a9a8c..8f4813a0b 100644 --- a/src/onefetch/image_backends/mod.rs +++ b/src/onefetch/image_backends/mod.rs @@ -12,17 +12,20 @@ pub trait ImageBackend { fn add_image(&self, lines: Vec, image: &DynamicImage, colors: usize) -> Result; } -#[cfg(not(windows))] pub fn get_best_backend() -> Option> { - if sixel::SixelBackend::supported() { - Some(Box::new(sixel::SixelBackend::new())) - } else if kitty::KittyBackend::supported() { + #[cfg(not(windows))] + if kitty::KittyBackend::supported() { Some(Box::new(kitty::KittyBackend::new())) } else if iterm::ITermBackend::supported() { Some(Box::new(iterm::ITermBackend::new())) + } else if sixel::SixelBackend::supported() { + Some(Box::new(sixel::SixelBackend::new())) } else { None } + + #[cfg(windows)] + None } pub fn get_image_backend(backend_name: &str) -> Option> { @@ -33,12 +36,8 @@ pub fn get_image_backend(backend_name: &str) -> Option> { "sixel" => Box::new(sixel::SixelBackend::new()) as Box, _ => unreachable!(), }); + #[cfg(windows)] let backend = None; backend } - -#[cfg(windows)] -pub fn get_best_backend() -> Option> { - None -}