Skip to content

Commit 34af6a9

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 890f3a4 commit 34af6a9

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
@@ -132,6 +132,25 @@ public fn void setGlobals(Globals* g) @(unused) { globals = g; }
132132

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

0 commit comments

Comments
 (0)