Skip to content

Commit 97cebe1

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 dc36701 commit 97cebe1

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
@@ -137,6 +137,25 @@ public fn void setGlobals(Globals* g) @(unused){
137137

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

0 commit comments

Comments
 (0)