added some color to the error messages (linux only)
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 20 Jun 2021 20:10:54 +0000 (15:10 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 20 Jun 2021 20:10:54 +0000 (15:10 -0500)
bin/onyx
include/onyxastnodes.h
modules/ui/components/slider.onyx
src/onyx.c
src/onyxerrors.c

index 3cdf33078f221ccec0230eb62cbeabdf107a06a3..695c6b31fd1ea80cbc63d2f70337d6aab1d2ffdf 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 3cf22675c532f510583adb2a41d42e748527e4a0..bda1433696a8d281a24786d60a0b6d57a045ec99 100644 (file)
@@ -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;
 
index d8a4262223743c60509fe34a84ee0c8fa87ceccf..f17c1ac024281230cfdf621c55ef4c669836f17b 100644 (file)
@@ -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);
index a6ff73c9e75c9186146ff0b0ef974e5241968932..07e8f2c3ca30e1e947c246c616b5866716eda179 100644 (file)
@@ -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;
             }
index 81a3cbabe0136b53dce8ff4b826ffa52ee7bbf85..5c25f63ef3c97dc744e8e05f45134160d649b06b 100644 (file)
@@ -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() {