diff --git a/src/onefetch/cli.rs b/src/onefetch/cli.rs index 4fca8c30e..2cc994a80 100644 --- a/src/onefetch/cli.rs +++ b/src/onefetch/cli.rs @@ -21,6 +21,7 @@ pub struct Cli { pub no_bold: bool, pub image: Option, pub image_backend: Option>, + pub image_colors: usize, pub no_merges: bool, pub no_color_blocks: bool, pub number_of_authors: usize, @@ -141,6 +142,16 @@ impl Cli { .possible_values(&possible_backends) .help("Which image BACKEND to use."), ) + .arg( + Arg::with_name("image-colors") + .long("image-colors") + .value_name("NUM") + .takes_value(true) + .max_values(1) + .possible_values(&["16", "32", "64", "128", "256"]) + .default_value("16") + .help("NUM of colors [16, 32, 64, 128, 256] to use in image backend."), + ) .arg( Arg::with_name("no-merge-commits") .long("no-merge-commits") @@ -215,6 +226,8 @@ impl Cli { None }; + let image_colors: usize = matches.value_of("image-colors").unwrap().parse().unwrap(); + let path = String::from(matches.value_of("input").unwrap()); let ascii_input = matches.value_of("ascii-input").map(String::from); @@ -254,6 +267,7 @@ impl Cli { no_bold, image, image_backend, + image_colors, no_merges, no_color_blocks, number_of_authors, diff --git a/src/onefetch/cli_utils.rs b/src/onefetch/cli_utils.rs index ac9cb4779..4d437b552 100644 --- a/src/onefetch/cli_utils.rs +++ b/src/onefetch/cli_utils.rs @@ -28,6 +28,7 @@ impl Printer { buf.push_str(&image_backend.add_image( info_lines.map(|s| format!("{}{}", center_pad, s)).collect(), custom_image, + self.info.config.image_colors )); } else { panic!("No image backend found") diff --git a/src/onefetch/image_backends/kitty.rs b/src/onefetch/image_backends/kitty.rs index 92caaa3f2..8ce7b7e86 100644 --- a/src/onefetch/image_backends/kitty.rs +++ b/src/onefetch/image_backends/kitty.rs @@ -77,7 +77,7 @@ impl KittyBackend { } impl super::ImageBackend for KittyBackend { - fn add_image(&self, lines: Vec, image: &DynamicImage) -> String { + fn add_image(&self, lines: Vec, image: &DynamicImage, _colors: usize) -> String { let tty_size = unsafe { let tty_size: winsize = std::mem::zeroed(); ioctl(STDOUT_FILENO, TIOCGWINSZ, &tty_size); diff --git a/src/onefetch/image_backends/mod.rs b/src/onefetch/image_backends/mod.rs index 676004a58..2925179cf 100644 --- a/src/onefetch/image_backends/mod.rs +++ b/src/onefetch/image_backends/mod.rs @@ -6,7 +6,7 @@ pub mod kitty; pub mod sixel; pub trait ImageBackend { - fn add_image(&self, lines: Vec, image: &DynamicImage) -> String; + fn add_image(&self, lines: Vec, image: &DynamicImage, colors: usize) -> String; } #[cfg(not(windows))] diff --git a/src/onefetch/image_backends/sixel.rs b/src/onefetch/image_backends/sixel.rs index 816ff8872..16398ea66 100644 --- a/src/onefetch/image_backends/sixel.rs +++ b/src/onefetch/image_backends/sixel.rs @@ -71,7 +71,7 @@ impl SixelBackend { } impl super::ImageBackend for SixelBackend { - fn add_image(&self, lines: Vec, image: &DynamicImage) -> String { + fn add_image(&self, lines: Vec, image: &DynamicImage, colors: usize) -> String { let tty_size = unsafe { let tty_size: winsize = std::mem::zeroed(); ioctl(STDOUT_FILENO, TIOCGWINSZ, &tty_size); @@ -97,7 +97,7 @@ impl super::ImageBackend for SixelBackend { // reduce the amount of colors using dithering colorops::dither( &mut rgba_image, - &NeuQuant::new(10, 16, flat_samples.image_slice().unwrap()), + &NeuQuant::new(10, colors, flat_samples.image_slice().unwrap()), ); let rgb_image = ImageBuffer::from_fn(rgba_image.width(), rgba_image.height(), |x, y| { let rgba_pixel = rgba_image.get_pixel(x, y);