@@ -20,12 +20,22 @@ import stdarg local;
2020
2121import color local;
2222
23- bool use_color = false;
2423bool show_debug = false;
2524bool show_timing = false;
2625
26+ const char* col_debug = color.Blue;
27+ const char* col_warning = color.Yellow;
28+ const char* col_error = color.Red;
29+ const char* col_timing = color.Blue;
30+ const char* col_normal = color.Normal;
31+
2732public fn void init() {
28- use_color = color.useColor();
33+ color.useColor();
34+ col_debug = color.getConfigColor("debug", color.Blue);
35+ col_warning = color.getConfigColor("warning", color.Yellow);
36+ col_error = color.getConfigColor("error", color.Red);
37+ col_timing = color.getConfigColor("timing", color.Blue);
38+ col_normal = color.normal;
2939}
3040
3141public fn void setDebug(bool enable) {
@@ -44,11 +54,7 @@ public fn void debug(const char* format @(printf_format), ...) {
4454 va_start(args, format);
4555 vsnprintf(buf, sizeof(buf), format, args);
4656 va_end(args);
47- if (use_color) {
48- printf("%s%s%s\n", color.Blue, buf, color.Normal);
49- } else {
50- printf("%s\n", buf);
51- }
57+ printf("%s%s%s\n", col_debug, buf, col_normal);
5258}
5359
5460public fn void log(const char* format @(printf_format), ...) {
@@ -66,11 +72,7 @@ public fn void warn(const char* format @(printf_format), ...) {
6672 va_start(args, format);
6773 vsnprintf(buf, sizeof(buf), format, args);
6874 va_end(args);
69- if (use_color) {
70- fprintf(stderr, "%swarning: %s%s\n", color.Yellow, buf, color.Normal);
71- } else {
72- fprintf(stderr, "warning: %s\n", buf);
73- }
75+ fprintf(stderr, "%swarning: %s%s\n", col_warning, buf, col_normal);
7476}
7577
7678public fn void error(const char* format @(printf_format), ...) {
@@ -79,11 +81,7 @@ public fn void error(const char* format @(printf_format), ...) {
7981 va_start(args, format);
8082 vsprintf(buf, format, args);
8183 va_end(args);
82- if (use_color) {
83- fprintf(stderr, "%serror: %s%s\n", color.Red, buf, color.Normal);
84- } else {
85- fprintf(stderr, "error: %s\n", buf);
86- }
84+ fprintf(stderr, "%serror: %s%s\n", col_error, buf, col_normal);
8785}
8886
8987public fn void error_diag(const char* loc, const char* format @(printf_format), ...) {
@@ -92,19 +90,11 @@ public fn void error_diag(const char* loc, const char* format @(printf_format),
9290 va_start(args, format);
9391 vsprintf(buf, format, args);
9492 va_end(args);
95- if (use_color) {
96- fprintf(stderr, "%s%s: error: %s%s\n", color.Red, loc, buf, color.Normal);
97- } else {
98- fprintf(stderr, "%s: error: %s\n", loc, buf);
99- }
93+ fprintf(stderr, "%s%s: error: %s%s\n", col_error, loc, buf, col_normal);
10094}
10195
10296public fn void log_time(const char* item, u64 duration) {
10397 if (!show_timing) return;
104- if (use_color) {
105- printf("%s%s took %d usec%s\n", color.Blue, item, duration, color.Normal);
106- } else {
107- printf("%s took %d usec\n", item, duration);
108- }
98+ printf("%s%s took %d usec%s\n", col_timing, item, duration, col_normal);
10999}
110100
0 commit comments