Skip to content

Commit ea19b41

Browse files
authored
add make_dark_theme and make_light_theme helpers
1 parent cb2f4e9 commit ea19b41

File tree

2 files changed

+143
-49
lines changed

2 files changed

+143
-49
lines changed

src/color_themes/fleet.rs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -175,52 +175,3 @@ pub const GRAY: &[crate::ColorMap] = &[
175175
cmap!(0, 0, 0, 0),
176176
cmap!(15, 0, 0, 128),
177177
];
178-
179-
pub const GRUVBOX_DARK2: Lazy<[crate::ColorMap; 256]> = Lazy::new(|| std::array::from_fn(|idx| {
180-
let idx = idx as u8;
181-
const fn gruvbox_gray(n: u8) -> u8 {
182-
let dark = 40u16;
183-
let light = 180u16;
184-
(dark + ((light - dark) * n as u16 + 11) / 23) as u8
185-
}
186-
const fn gruvbox_gray_inv(n: u8) -> u8 {
187-
let light = 180u16;
188-
let dark = 40u16;
189-
(light - ((light - dark) * n as u16 + 11) / 23) as u8
190-
}
191-
192-
const fn cube_chan(i: u8, steps: usize) -> u8 {
193-
((i as u16 * 110 + ((steps - 1) / 2) as u16) / (steps as u16 - 1)) as u8
194-
}
195-
match idx {
196-
0 => cmap!(idx, 235, 219, 178),
197-
1 => cmap!(idx, 251, 73, 52),
198-
2 => cmap!(idx, 184, 187, 38),
199-
3 => cmap!(idx, 250, 189, 47),
200-
4 => cmap!(idx, 131, 165, 152),
201-
5 => cmap!(idx, 211, 134, 155),
202-
6 => cmap!(idx, 142, 192, 124),
203-
7 => cmap!(idx, 60, 60, 60),
204-
15 => cmap!(idx, 131, 165, 152),
205-
49 => cmap!(idx, 40, 40, 40),
206-
32..=55 => {
207-
let g = gruvbox_gray_inv(idx - 32);
208-
cmap!(idx, g, g, g)
209-
}
210-
56..=255 => {
211-
let n = idx - 56;
212-
let b = n / (5 * 8);
213-
let r = (n / 8) % 5;
214-
let g = n % 8;
215-
let r1 = cube_chan(r, 5);
216-
let g1 = cube_chan(g, 8);
217-
let b1 = cube_chan(b, 5);
218-
cmap!(idx,
219-
r1,
220-
g1,
221-
b1
222-
)
223-
}
224-
_ => cmap!(idx, 0, 0, 0),
225-
}
226-
}));

src/color_themes/fleet2.rs

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
use crate::{cmap, ColorMap};
2+
use fltk::utils::oncelock::Lazy;
3+
4+
const fn gray_ramp(light: u8, dark: u8, n: u8) -> u8 {
5+
let l = light as u16;
6+
let d = dark as u16;
7+
(d + ((l - d) * n as u16 + 11) / 23) as u8
8+
}
9+
10+
const fn gray_ramp_inv(light: u8, dark: u8, n: u8) -> u8 {
11+
let l = light as u16;
12+
let d = dark as u16;
13+
(l - ((l - d) * n as u16 + 11) / 23) as u8
14+
}
15+
16+
const fn cube_chan(i: u8, steps: u8, max: u8) -> u8 {
17+
((i as u16 * max as u16 + ((steps - 1) / 2) as u16)
18+
/ (steps as u16 - 1)) as u8
19+
}
20+
21+
pub fn make_dark_theme(
22+
overrides: &'static [(u8, u8, u8, u8)],
23+
ramp: (u8, u8),
24+
cube_max: u8,
25+
) -> Lazy<[ColorMap; 256]> {
26+
let (ramp_light, ramp_dark) = ramp;
27+
28+
Lazy::new(move || {
29+
std::array::from_fn(|idx| {
30+
let idx8 = idx as u8;
31+
32+
if let Some(&(_, r, g, b)) =
33+
overrides.iter().rev().find(|&&(i, ..)| i == idx8)
34+
{
35+
return cmap!(idx8, r, g, b);
36+
}
37+
38+
if (32..=55).contains(&idx) {
39+
let shade = gray_ramp_inv(ramp_light, ramp_dark, idx8 - 32);
40+
return cmap!(idx8, shade, shade, shade);
41+
}
42+
43+
if idx >= 56 {
44+
let n = idx8 - 56;
45+
let b = n / (5 * 8);
46+
let r = (n / 8) % 5;
47+
let g = n % 8;
48+
let rr = cube_chan(r, 5, cube_max);
49+
let gg = cube_chan(g, 8, cube_max);
50+
let bb = cube_chan(b, 5, cube_max);
51+
return cmap!(idx8, rr, gg, bb);
52+
}
53+
54+
cmap!(idx8, 0, 0, 0)
55+
})
56+
})
57+
}
58+
59+
pub fn make_light_theme(
60+
overrides: &'static [(u8, u8, u8, u8)],
61+
ramp: (u8, u8),
62+
cube_max: u8,
63+
) -> once_cell::sync::Lazy<[ColorMap; 256]> {
64+
let (ramp_dark, ramp_light) = ramp;
65+
66+
once_cell::sync::Lazy::new(move || {
67+
std::array::from_fn(|idx| {
68+
let idx8 = idx as u8;
69+
70+
if let Some(&(_, r, g, b)) =
71+
overrides.iter().rev().find(|&&(i, ..)| i == idx8)
72+
{
73+
return cmap!(idx8, r, g, b);
74+
}
75+
76+
if (32..=55).contains(&idx) {
77+
let shade = gray_ramp(ramp_dark, ramp_light, idx8 - 32);
78+
return cmap!(idx8, shade, shade, shade);
79+
}
80+
81+
if idx >= 56 {
82+
let n = idx8 - 56;
83+
let b = n / (5 * 8);
84+
let r = (n / 8) % 5;
85+
let g = n % 8;
86+
let rr = cube_chan(r, 5, cube_max);
87+
let gg = cube_chan(g, 8, cube_max);
88+
let bb = cube_chan(b, 5, cube_max);
89+
return cmap!(idx8, rr, gg, bb);
90+
}
91+
92+
cmap!(idx8, 0, 0, 0)
93+
})
94+
})
95+
}
96+
97+
pub const GRUVBOX_DARK: Lazy<[crate::ColorMap; 256]> = make_dark_theme(
98+
&[
99+
(0, 235, 219, 178),
100+
(1, 251, 73, 52),
101+
(2, 184, 187, 38),
102+
(3, 250, 189, 47),
103+
(4, 131, 165, 152),
104+
(5, 211, 134, 155),
105+
(6, 142, 192, 124),
106+
(7, 60, 60, 60),
107+
(15, 131, 165, 152),
108+
(49, 40, 40, 40),
109+
],
110+
(180, 40), // gray ramp light → dark
111+
110,
112+
);
113+
114+
pub const MONOKAI_DARK: Lazy<[ColorMap; 256]> = make_dark_theme(
115+
&[
116+
( 0, 249,249,249), // fg
117+
( 1, 249, 38,114), // red
118+
( 2, 166,226, 46), // green
119+
( 3, 253,151, 31), // yellow/orange
120+
( 4, 102,217,239), // cyan
121+
( 5, 174,129,255), // magenta
122+
( 7, 51, 52, 46), // darkest bg
123+
(49, 39, 40, 34), // FL_GRAY
124+
],
125+
(0xCC, 0x27), // light ≈ #CCCBB3, dark ≈ #272822
126+
110,
127+
);
128+
129+
pub const SOLARIZED_LIGHT: Lazy<[ColorMap; 256]> = make_light_theme(
130+
&[
131+
(0 , 42, 42, 42), // label text (base00)
132+
(7 , 253, 246, 227), // main bg (base3)
133+
(49, 238, 232, 213), // FL_GRAY (base2)
134+
(1 , 220, 50, 47), // error red
135+
(2 , 133, 153, 0), // ok green
136+
(3 , 181, 137, 0), // warning yellow
137+
(4 , 38, 139, 210), // info blue
138+
(5 , 211, 54, 130), // magenta
139+
(15, 38, 139, 210), // check-mark colour
140+
],
141+
(200, 255), // gray ramp: 32 = #C8C8C8, 55 = #FFFFFF
142+
180, // cube max: keep shadows mildly muted
143+
);

0 commit comments

Comments
 (0)