1#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
2pub struct Color(pub u8, pub u8, pub u8);
3
4impl Color {
5 pub const fn into_u32(self) -> u32 {
6 let r = self.0 as u32;
7 let g = self.1 as u32;
8 let b = self.2 as u32;
9 r << 16 | g << 8 | b
10 }
11
12 pub const fn from_u32(hex: u32) -> Color {
13 Color(
14 ((hex >> 16) & 0xff) as _,
15 ((hex >> 8) & 0xff) as _,
16 (hex & 0xff) as _,
17 )
18 }
19}
20
21macro_rules! theme_colors {
22 ($($color:ident,)*) => {
23 pub static THEME_COLOR_NAMES: &[&str] = &[$(stringify!($color),)*];
24
25 pub struct Theme {
26 $(pub $color: Color,)*
27 }
28
29 impl Theme {
30 pub fn color_from_name(&mut self, name: &str) -> Option<&mut Color> {
31 match name {
32 $(stringify!($color) => Some(&mut self.$color),)*
33 _ => None,
34 }
35 }
36 }
37 }
38}
39
40theme_colors! {
41 normal_background,
42 active_background,
43 breakpoint_background,
44 highlight,
45 normal_cursor,
46 select_cursor,
47 insert_cursor,
48 inactive_cursor,
49 statusbar_active_background,
50 statusbar_inactive_background,
51
52 token_whitespace,
53 token_text,
54 token_comment,
55 token_keyword,
56 token_type,
57 token_symbol,
58 token_string,
59 token_literal,
60}
61
62impl Default for Theme {
63 fn default() -> Self {
64 gruvbox_theme()
65 }
66}
67
68pub fn gruvbox_theme() -> Theme {
69 Theme {
70 normal_background: Color::from_u32(0x1d2021),
71 active_background: Color::from_u32(0x282828),
72 breakpoint_background: Color::from_u32(0x3d2021),
73 highlight: Color::from_u32(0xfabd2f),
74 normal_cursor: Color::from_u32(0xcc241d),
75 insert_cursor: Color::from_u32(0xfabd2f),
76 select_cursor: Color::from_u32(0x458588),
77 inactive_cursor: Color::from_u32(0x504945),
78 statusbar_active_background: Color::from_u32(0x504945),
79 statusbar_inactive_background: Color::from_u32(0x282828),
80
81 token_whitespace: Color::from_u32(0x504945),
82 token_text: Color::from_u32(0xebdbb2),
83 token_comment: Color::from_u32(0x7c6f64),
84 token_keyword: Color::from_u32(0xfe8019),
85 token_type: Color::from_u32(0x8ec07c),
86 token_symbol: Color::from_u32(0xa89984),
87 token_string: Color::from_u32(0xb8bb26),
88 token_literal: Color::from_u32(0xd3869b),
89 }
90}