1use anyhow::Result;
2use image::DynamicImage;
3
4#[derive(clap::ValueEnum, Clone, PartialEq, Eq, Debug)]
5pub enum ImageProtocol {
6 Kitty,
7 Sixel,
8 Iterm,
9}
10
11#[cfg(not(windows))]
12pub mod iterm;
13#[cfg(not(windows))]
14pub mod kitty;
15#[cfg(not(windows))]
16pub mod sixel;
17
18pub trait ImageBackend {
19 fn add_image(&self, lines: Vec<String>, image: &DynamicImage, colors: usize) -> Result<String>;
20}
21
22pub fn get_best_backend() -> Result<Option<Box<dyn ImageBackend>>> {
23 #[cfg(not(windows))]
24 if sixel::SixelBackend::supported()? {
25 Ok(Some(Box::new(sixel::SixelBackend)))
26 } else if kitty::KittyBackend::supported()? {
27 Ok(Some(Box::new(kitty::KittyBackend)))
28 } else if iterm::ITermBackend::supported() {
29 Ok(Some(Box::new(iterm::ITermBackend)))
30 } else {
31 Ok(None)
32 }
33
34 #[cfg(windows)]
35 Ok(None)
36}
37
38#[allow(unused_variables)]
39pub fn get_image_backend(image_protocol: ImageProtocol) -> Option<Box<dyn ImageBackend>> {
40 #[cfg(not(windows))]
41 let backend = Some(match image_protocol {
42 ImageProtocol::Kitty => Box::new(kitty::KittyBackend) as Box<dyn ImageBackend>,
43 ImageProtocol::Iterm => Box::new(iterm::ITermBackend) as Box<dyn ImageBackend>,
44 ImageProtocol::Sixel => Box::new(sixel::SixelBackend) as Box<dyn ImageBackend>,
45 });
46
47 #[cfg(windows)]
48 let backend = None;
49 backend
50}