colors_by_example/base16.rs
1//! Platform dependent 4-bit color codes.
2//!
3//! [3-bit and 4-bit Colors](https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit)
4
5/// System defined colors.
6///
7/// Different platform has different palette.
8/// Actual values are configurable in terminal emulators.
9#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
10pub struct Base16(pub [[u8; 3]; 16]);
11
12impl Base16 {
13 pub fn new() -> Self {
14 Base16::default()
15 }
16}
17
18impl Default for Base16 {
19 fn default() -> Self {
20 DEFAULT
21 }
22}
23
24#[cfg(target_os = "macos")]
25pub use TERMINAL_APP as DEFAULT;
26
27#[cfg(target_os = "windows")]
28pub use WIN10_CONSOLE as DEFAULT;
29
30#[cfg(not(any(target_os = "macos", target_os = "windows")))]
31pub use WIN10_CONSOLE as DEFAULT;
32
33// Values from Terminal.app
34pub const TERMINAL_APP: Base16 = Base16([
35 // standard colors
36 [0, 0, 0], // Black
37 [153, 0, 0], // Red
38 [0, 166, 0], // Green
39 [153, 153, 0], // Yellow
40 [0, 0, 178], // Blue
41 [178, 0, 178], // Magenta
42 [0, 166, 178], // Cyan
43 [191, 191, 191], // White
44 // high intensity colors
45 [102, 102, 102], // Bright Black (Gray)
46 [230, 0, 0], // Bright Red
47 [0, 217, 0], // Bright Green
48 [230, 230, 0], // Bright Yellow
49 [0, 0, 255], // Bright Blue
50 [230, 0, 230], // Bright Magenta
51 [0, 230, 230], // Bright Cyan
52 [230, 230, 230], // Bright White
53]);
54
55// Values from: https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
56pub const WIN10_CONSOLE: Base16 = Base16([
57 // standard colors
58 [12, 12, 12], // Black
59 [197, 15, 31], // Red
60 [19, 161, 14], // Green
61 [193, 156, 0], // Yellow
62 [0, 55, 218], //Blue
63 [136, 23, 152], //Magenta
64 [58, 150, 221], //Cyan
65 [204, 204, 204], //White
66 // high intensity colors
67 [118, 118, 118], // Bright Black (Gray)
68 [231, 72, 86], // Bright Red
69 [22, 198, 12], // Bright Green
70 [249, 241, 165], //Bright Yellow
71 [59, 120, 255], //Bright Blue
72 [180, 0, 158], // Bright Magenta
73 [97, 214, 214], //Bright Cyan
74 [242, 242, 242], //Bright White
75]);
76
77// Values from: https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
78pub const XTERM: Base16 = Base16([
79 // standard colors
80 [0, 0, 0], // Black
81 [205, 0, 0], // Red
82 [0, 205, 0], // Green
83 [205, 205, 0], // Yellow
84 [0, 0, 238], // Blue
85 [205, 0, 205], // Magenta
86 [0, 205, 205], // Cyan
87 [229, 229, 229], // White
88 // high intensity colors
89 [127, 127, 127], // Bright Black (Gray)
90 [255, 0, 0], // Bright Red
91 [0, 255, 0], // Bright Green
92 [255, 255, 0], // Bright Yellow
93 [92, 92, 255], // Bright Blue
94 [255, 0, 255], // Bright Magenta
95 [0, 255, 255], // Bright Cyan
96 [255, 255, 255], // Bright White
97]);