Skip to content

Commit 69306bd

Browse files
authored
Merge pull request #271 from yoichi/sixel-more-color
Use more color than 16 in sixel graphics
2 parents c2883d1 + 3648aaa commit 69306bd

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

src/onefetch/cli.rs

+14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Cli {
2121
pub no_bold: bool,
2222
pub image: Option<DynamicImage>,
2323
pub image_backend: Option<Box<dyn image_backends::ImageBackend>>,
24+
pub image_colors: usize,
2425
pub no_merges: bool,
2526
pub no_color_blocks: bool,
2627
pub number_of_authors: usize,
@@ -141,6 +142,16 @@ impl Cli {
141142
.possible_values(&possible_backends)
142143
.help("Which image BACKEND to use."),
143144
)
145+
.arg(
146+
Arg::with_name("image-colors")
147+
.long("image-colors")
148+
.value_name("NUM")
149+
.takes_value(true)
150+
.max_values(1)
151+
.possible_values(&["16", "32", "64", "128", "256"])
152+
.default_value("16")
153+
.help("NUM of colors [16, 32, 64, 128, 256] to use in image backend."),
154+
)
144155
.arg(
145156
Arg::with_name("no-merge-commits")
146157
.long("no-merge-commits")
@@ -215,6 +226,8 @@ impl Cli {
215226
None
216227
};
217228

229+
let image_colors: usize = matches.value_of("image-colors").unwrap().parse().unwrap();
230+
218231
let path = String::from(matches.value_of("input").unwrap());
219232

220233
let ascii_input = matches.value_of("ascii-input").map(String::from);
@@ -254,6 +267,7 @@ impl Cli {
254267
no_bold,
255268
image,
256269
image_backend,
270+
image_colors,
257271
no_merges,
258272
no_color_blocks,
259273
number_of_authors,

src/onefetch/cli_utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl<W: Write> Printer<W> {
2828
buf.push_str(&image_backend.add_image(
2929
info_lines.map(|s| format!("{}{}", center_pad, s)).collect(),
3030
custom_image,
31+
self.info.config.image_colors
3132
));
3233
} else {
3334
panic!("No image backend found")

src/onefetch/image_backends/kitty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl KittyBackend {
7777
}
7878

7979
impl super::ImageBackend for KittyBackend {
80-
fn add_image(&self, lines: Vec<String>, image: &DynamicImage) -> String {
80+
fn add_image(&self, lines: Vec<String>, image: &DynamicImage, _colors: usize) -> String {
8181
let tty_size = unsafe {
8282
let tty_size: winsize = std::mem::zeroed();
8383
ioctl(STDOUT_FILENO, TIOCGWINSZ, &tty_size);

src/onefetch/image_backends/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub mod kitty;
66
pub mod sixel;
77

88
pub trait ImageBackend {
9-
fn add_image(&self, lines: Vec<String>, image: &DynamicImage) -> String;
9+
fn add_image(&self, lines: Vec<String>, image: &DynamicImage, colors: usize) -> String;
1010
}
1111

1212
#[cfg(not(windows))]

src/onefetch/image_backends/sixel.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl SixelBackend {
7171
}
7272

7373
impl super::ImageBackend for SixelBackend {
74-
fn add_image(&self, lines: Vec<String>, image: &DynamicImage) -> String {
74+
fn add_image(&self, lines: Vec<String>, image: &DynamicImage, colors: usize) -> String {
7575
let tty_size = unsafe {
7676
let tty_size: winsize = std::mem::zeroed();
7777
ioctl(STDOUT_FILENO, TIOCGWINSZ, &tty_size);
@@ -97,7 +97,7 @@ impl super::ImageBackend for SixelBackend {
9797
// reduce the amount of colors using dithering
9898
colorops::dither(
9999
&mut rgba_image,
100-
&NeuQuant::new(10, 16, flat_samples.image_slice().unwrap()),
100+
&NeuQuant::new(10, colors, flat_samples.image_slice().unwrap()),
101101
);
102102
let rgb_image = ImageBuffer::from_fn(rgba_image.width(), rgba_image.height(), |x, y| {
103103
let rgba_pixel = rgba_image.get_pixel(x, y);

0 commit comments

Comments
 (0)