stackdump_trace/
render_colors.rs1use colored::{ColoredString, Colorize};
2use std::fmt::Display;
3
4#[derive(Debug, Clone, Copy, strum_macros::Display, strum_macros::EnumString)]
5pub enum Theme {
6 None,
7 Dark,
8}
9
10impl ThemeColors for Theme {
11 fn color_numeric_value<S: Display>(&self, text: S) -> ColoredString {
12 match self {
13 Theme::None => NoTheme.color_numeric_value(text),
14 Theme::Dark => DarkTheme.color_numeric_value(text),
15 }
16 }
17
18 fn color_invalid<S: Display>(&self, text: S) -> ColoredString {
19 match self {
20 Theme::None => NoTheme.color_invalid(text),
21 Theme::Dark => DarkTheme.color_invalid(text),
22 }
23 }
24
25 fn color_string_value<S: Display>(&self, text: S) -> ColoredString {
26 match self {
27 Theme::None => NoTheme.color_string_value(text),
28 Theme::Dark => DarkTheme.color_string_value(text),
29 }
30 }
31
32 fn color_type_name<S: Display>(&self, text: S) -> ColoredString {
33 match self {
34 Theme::None => NoTheme.color_type_name(text),
35 Theme::Dark => DarkTheme.color_type_name(text),
36 }
37 }
38
39 fn color_variable_name<S: Display>(&self, text: S) -> ColoredString {
40 match self {
41 Theme::None => NoTheme.color_variable_name(text),
42 Theme::Dark => DarkTheme.color_variable_name(text),
43 }
44 }
45
46 fn color_enum_member<S: Display>(&self, text: S) -> ColoredString {
47 match self {
48 Theme::None => NoTheme.color_enum_member(text),
49 Theme::Dark => DarkTheme.color_enum_member(text),
50 }
51 }
52
53 fn color_url<S: Display>(&self, text: S) -> ColoredString {
54 match self {
55 Theme::None => NoTheme.color_url(text),
56 Theme::Dark => DarkTheme.color_url(text),
57 }
58 }
59
60 fn color_function<S: Display>(&self, text: S) -> ColoredString {
61 match self {
62 Theme::None => NoTheme.color_function(text),
63 Theme::Dark => DarkTheme.color_function(text),
64 }
65 }
66
67 fn color_info<S: Display>(&self, text: S) -> ColoredString {
68 match self {
69 Theme::None => NoTheme.color_info(text),
70 Theme::Dark => DarkTheme.color_info(text),
71 }
72 }
73}
74
75pub struct DarkTheme;
76
77impl ThemeColors for DarkTheme {
78 fn color_numeric_value<S: Display>(&self, text: S) -> ColoredString {
79 text.to_string().truecolor(0xb5, 0xce, 0xa8)
80 }
81 fn color_invalid<S: Display>(&self, text: S) -> ColoredString {
82 text.to_string().truecolor(0xf4, 0x47, 0x47)
83 }
84 fn color_string_value<S: Display>(&self, text: S) -> ColoredString {
85 text.to_string().truecolor(0xce, 0x91, 0x78)
86 }
87 fn color_type_name<S: Display>(&self, text: S) -> ColoredString {
88 text.to_string().truecolor(0x4e, 0xc9, 0xb0)
89 }
90 fn color_variable_name<S: Display>(&self, text: S) -> ColoredString {
91 text.to_string().truecolor(0x9c, 0xdc, 0xfe)
92 }
93 fn color_enum_member<S: Display>(&self, text: S) -> ColoredString {
94 text.to_string().truecolor(0x9c, 0xdc, 0xfe)
95 }
96 fn color_url<S: Display>(&self, text: S) -> ColoredString {
97 text.to_string().bright_black().underline()
98 }
99 fn color_function<S: Display>(&self, text: S) -> ColoredString {
100 text.to_string().truecolor(0xdc, 0xdc, 0xaa)
101 }
102 fn color_info<S: Display>(&self, text: S) -> ColoredString {
103 text.to_string().bright_black()
104 }
105}
106
107pub struct NoTheme;
108
109impl ThemeColors for NoTheme {
110 fn color_numeric_value<S: Display>(&self, text: S) -> ColoredString {
111 text.to_string().as_str().into()
112 }
113
114 fn color_invalid<S: Display>(&self, text: S) -> ColoredString {
115 text.to_string().as_str().into()
116 }
117
118 fn color_string_value<S: Display>(&self, text: S) -> ColoredString {
119 text.to_string().as_str().into()
120 }
121
122 fn color_type_name<S: Display>(&self, text: S) -> ColoredString {
123 text.to_string().as_str().into()
124 }
125
126 fn color_variable_name<S: Display>(&self, text: S) -> ColoredString {
127 text.to_string().as_str().into()
128 }
129
130 fn color_enum_member<S: Display>(&self, text: S) -> ColoredString {
131 text.to_string().as_str().into()
132 }
133
134 fn color_url<S: Display>(&self, text: S) -> ColoredString {
135 text.to_string().as_str().into()
136 }
137
138 fn color_function<S: Display>(&self, text: S) -> ColoredString {
139 text.to_string().as_str().into()
140 }
141
142 fn color_info<S: Display>(&self, text: S) -> ColoredString {
143 text.to_string().as_str().into()
144 }
145}
146
147pub trait ThemeColors {
148 fn color_numeric_value<S: Display>(&self, text: S) -> ColoredString;
149 fn color_invalid<S: Display>(&self, text: S) -> ColoredString;
150 fn color_string_value<S: Display>(&self, text: S) -> ColoredString;
151 fn color_type_name<S: Display>(&self, text: S) -> ColoredString;
152 fn color_variable_name<S: Display>(&self, text: S) -> ColoredString;
153 fn color_enum_member<S: Display>(&self, text: S) -> ColoredString;
154 fn color_url<S: Display>(&self, text: S) -> ColoredString;
155 fn color_function<S: Display>(&self, text: S) -> ColoredString;
156 fn color_info<S: Display>(&self, text: S) -> ColoredString;
157}