Skip to content

Commit

Permalink
fix image backend detection
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Nov 21, 2020
1 parent 8397b9d commit 7d92b48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
5 changes: 0 additions & 5 deletions src/onefetch/image_backends/kitty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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();
Expand Down
17 changes: 8 additions & 9 deletions src/onefetch/image_backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ pub trait ImageBackend {
fn add_image(&self, lines: Vec<String>, image: &DynamicImage, colors: usize) -> Result<String>;
}

#[cfg(not(windows))]
pub fn get_best_backend() -> Option<Box<dyn ImageBackend>> {
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<Box<dyn ImageBackend>> {
Expand All @@ -33,12 +36,8 @@ pub fn get_image_backend(backend_name: &str) -> Option<Box<dyn ImageBackend>> {
"sixel" => Box::new(sixel::SixelBackend::new()) as Box<dyn ImageBackend>,
_ => unreachable!(),
});

#[cfg(windows)]
let backend = None;
backend
}

#[cfg(windows)]
pub fn get_best_backend() -> Option<Box<dyn ImageBackend>> {
None
}

0 comments on commit 7d92b48

Please sign in to comment.