Skip to content

Commit 417aeb0

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 99c34ee commit 417aeb0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
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);

generator/c2_trace.c2

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ fn bool match_name(const char *name, const char *pattern) {
4040
}
4141
return (!c1 && (c2 == ',' || c2 == ';'));
4242
}
43-
return false;
4443
}
4544

4645
fn bool match_pattern(const char *name, const char *pattern) {

0 commit comments

Comments
 (0)