pic/previewer/
mod.rs

1use crate::options::Options;
2use crate::result::Result;
3use crate::support::Protocol;
4use std::io::Write;
5
6mod blocks;
7mod iterm;
8mod kitty;
9mod sixel;
10
11/// Preview an image to stdout with the given options
12pub fn preview(stdout: &mut impl Write, options: &mut Options) -> Result {
13    let protocol = Protocol::choose(options);
14    let image_paths = options.path.clone();
15    // If there is more than one path, render `-y` flag useless
16    // TODO: Does not work if the only path is a directory
17    if options.y.is_some() && image_paths.len() > 1 {
18        options.y = None;
19        // Notify about spacing flag
20    }
21
22    for image_path in &image_paths {
23        if image_path.is_dir() {
24            continue;
25        }
26
27        match protocol {
28            Protocol::Kitty => kitty::preview(stdout, image_path, options)?,
29            Protocol::Iterm => iterm::preview(stdout, image_path, options)?,
30            Protocol::Sixel => sixel::preview(stdout, image_path, options)?,
31            Protocol::Blocks => blocks::preview(stdout, image_path, options)?,
32        }
33    }
34
35    Ok(())
36}