Skip to content

Commit 3b5aa5f

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 7805001 commit 3b5aa5f

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

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

0 commit comments

Comments
 (0)