1 use crate::commands::prelude::*;
2 use crate::hdcanvas::Canvas;
3
4 use pastel::ansi::{Brush, Mode};
5
6 pub struct ColorCheckCommand;
7
print_board(out: &mut Output, config: &Config, mode: Mode) -> Result<()>8 fn print_board(out: &mut Output, config: &Config, mode: Mode) -> Result<()> {
9 // These colors have been chosen/computed such that the perceived color difference (CIE delta-E
10 // 2000) to the closest ANSI 8-bit color is maximal.
11 let c1 = Color::from_rgb(73, 39, 50);
12 let c2 = Color::from_rgb(16, 51, 30);
13 let c3 = Color::from_rgb(29, 54, 90);
14
15 let width = config.colorcheck_width;
16
17 let mut canvas = Canvas::new(
18 width + 2 * config.padding,
19 3 * width + 3 * config.padding,
20 Brush::from_mode(Some(mode)),
21 );
22
23 canvas.draw_rect(config.padding, config.padding, width, width, &c1);
24
25 canvas.draw_rect(
26 config.padding,
27 2 * config.padding + width,
28 width,
29 width,
30 &c2,
31 );
32
33 canvas.draw_rect(
34 config.padding,
35 3 * config.padding + 2 * width,
36 width,
37 width,
38 &c3,
39 );
40
41 canvas.print(out.handle)
42 }
43
44 impl GenericCommand for ColorCheckCommand {
run(&self, out: &mut Output, _: &ArgMatches, config: &Config) -> Result<()>45 fn run(&self, out: &mut Output, _: &ArgMatches, config: &Config) -> Result<()> {
46 writeln!(out.handle, "\n8-bit mode:")?;
47 print_board(out, config, Mode::Ansi8Bit)?;
48
49 writeln!(out.handle, "24-bit mode:")?;
50 print_board(out, config, Mode::TrueColor)?;
51
52 writeln!(
53 out.handle,
54 "If your terminal emulator supports 24-bit colors, you should see three square color \
55 panels in the lower row and the colors should look similar (but slightly different \
56 from) the colors in the top row panels.\nThe panels in the lower row should look \
57 like squares that are filled with a uniform color (no stripes or other artifacts).\n\
58 \n\
59 You can also open https://github.com/sharkdp/pastel/blob/master/doc/colorcheck.md in \
60 a browser to compare how the output should look like."
61 )?;
62
63 Ok(())
64 }
65 }
66