Skip to content

Commit b83b244

Browse files
committed
Compiler: support dark-mode
* disable colors if `C2_COLORS` environment variable is set to `none` * use brighter text colors in terminals with dark background by testing - if C2_COLORS is set to `dark` - if COLORFGBG specifies 0 background color
1 parent 9817258 commit b83b244

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

ast/utils.c2

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,25 @@ public fn void setGlobals(Globals* g) @(unused) { globals = g; }
133133

134134
// wordsize in bytes, must NOT be called from Plugin!
135135
public fn void initialize(Context* c, string_pool.Pool* astPool, u32 wordsize, bool use_color) {
136+
137+
if (use_color) {
138+
// adjust colors for readability on dark mode terminals
139+
const char* colorfgbg = stdlib.getenv("COLORFGBG");
140+
const char* c2_colors = stdlib.getenv("C2_COLORS");
141+
if (c2_colors && !string.strncmp(c2_colors, "none", 4)) {
142+
use_color = false;
143+
} else
144+
if ((c2_colors && !string.strncmp(c2_colors, "dark", 4))
145+
|| (colorfgbg && *colorfgbg && !string.strcmp(colorfgbg + 1, ";0"))) {
146+
// use brighter colors in dark mode
147+
col_Attr = color.Bblue;
148+
col_Template = color.Bgreen;
149+
col_Type = color.Bgreen;
150+
col_Error = color.Bred;
151+
col_Calc = color.Byellow;
152+
}
153+
}
154+
136155
globals = stdlib.malloc(sizeof(Globals));
137156
globals.pointers.init(c);
138157
globals.string_types.init(c);

0 commit comments

Comments
 (0)