From: Brendan Hansen Date: Sun, 20 Jun 2021 20:10:54 +0000 (-0500) Subject: added some color to the error messages (linux only) X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=13896a226de541bb9cdc251af8afebeb34efd1c9;p=onyx.git added some color to the error messages (linux only) --- diff --git a/bin/onyx b/bin/onyx index 3cdf3307..695c6b31 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 3cf22675..bda14336 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -1128,6 +1128,7 @@ struct CompileOptions { b32 print_function_mappings : 1; b32 print_static_if_results : 1; b32 print_notes : 1; + b32 no_colors : 1; b32 use_post_mvp_features : 1; diff --git a/modules/ui/components/slider.onyx b/modules/ui/components/slider.onyx index d8a42622..f17c1ac0 100644 --- a/modules/ui/components/slider.onyx +++ b/modules/ui/components/slider.onyx @@ -75,8 +75,6 @@ slider :: (use r: Rectangle, value: ^$T, min_value: T, max_value: T, text: str, #private_file adjust_slider_value :: #match { - @Incomplete // the step parameter is ignored. - // Integers need to be (value: ^i32, x: f32, width: f32, min_value: i32, max_value: i32) { step_width := width / ~~math.abs(max_value - min_value); percent := (x + step_width / 2) / width; @@ -84,7 +82,6 @@ adjust_slider_value :: #match { *value = math.clamp(*value, min_value, max_value); }, - @Incomplete // the step parameter is ignored. (value: ^$T, x: f32, width: f32, min_value: T, max_value: T) { percent := x / width; *value = math.lerp(percent, min_value, max_value); diff --git a/src/onyx.c b/src/onyx.c index a6ff73c9..07e8f2c3 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -48,6 +48,7 @@ static const char* docstring = "Onyx compiler version " VERSION "\n" "\t--print-function-mappings Prints a mapping from WASM function index to source location.\n" "\t--print-static-if-results Prints the conditional result of each #if statement. Useful for debugging.\n" "\t--print-notes Prints the location of notes throughout the loaded code.\n" + "\t--no-colors Disables colors in the error message\n" "\n"; @@ -105,6 +106,9 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg else if (!strcmp(argv[i], "--print-notes")) { options.print_notes = 1; } + else if (!strcmp(argv[i], "--no-colors")) { + options.no_colors = 1; + } else if (!strcmp(argv[i], "--use-post-mvp-features")) { options.use_post_mvp_features = 1; } diff --git a/src/onyxerrors.c b/src/onyxerrors.c index 81a3cbab..5c25f63e 100644 --- a/src/onyxerrors.c +++ b/src/onyxerrors.c @@ -15,11 +15,18 @@ void onyx_errors_init(bh_arr(bh_file_contents)* files) { static void print_detailed_message(OnyxError* err, bh_file_contents* fc) { bh_printf("(%s:%l,%l) %s\n", err->pos.filename, err->pos.line, err->pos.column, err->text); + b32 colored_printing = 0; + #ifdef _BH_LINUX + colored_printing = !context.options->no_colors; + #endif + i32 linelength = 0; char* walker = err->pos.line_start; while (*walker != '\n') linelength++, walker++; + if (colored_printing) bh_printf("\033[90m"); i32 numlen = bh_printf(" %d | ", err->pos.line); + if (colored_printing) bh_printf("\033[94m"); bh_printf("%b\n", err->pos.line_start, linelength); char* pointer_str = bh_alloc_array(global_scratch_allocator, char, linelength + numlen); @@ -28,7 +35,10 @@ static void print_detailed_message(OnyxError* err, bh_file_contents* fc) { pointer_str[err->pos.column + numlen - 2] = '^'; pointer_str[err->pos.column + numlen + err->pos.length - 1] = 0; + if (colored_printing) bh_printf("\033[91m"); bh_printf("%s\n", pointer_str); + + if (colored_printing) bh_printf("\033[97m"); } void onyx_errors_print() {