diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 077bcc15b..675f32bb6 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -900,16 +900,7 @@ static void setup_bool_define(const char *id, bool value) setup_define(id, expr_new_const_bool(INVALID_SPAN, type_bool, value)); } -#if FETCH_AVAILABLE -const char * vendor_fetch_single(const char* lib, const char* path) -{ - const char *resource = str_printf("/c3lang/vendor/releases/download/latest/%s.c3l", lib); - const char *destination = file_append_path(path, str_printf("%s.c3l", lib)); - const char *error = download_file("https://github.com", resource, destination); - return error; -} - -static bool use_ansi(void) +bool use_ansi(void) { switch (compiler.context.ansi) { @@ -927,6 +918,15 @@ static bool use_ansi(void) #endif } +#if FETCH_AVAILABLE +const char * vendor_fetch_single(const char* lib, const char* path) +{ + const char *resource = str_printf("/c3lang/vendor/releases/download/latest/%s.c3l", lib); + const char *destination = file_append_path(path, str_printf("%s.c3l", lib)); + const char *error = download_file("https://github.com", resource, destination); + return error; +} + #define PROGRESS_BAR_LENGTH 35 void update_progress_bar(const char* lib, int current_step, int total_steps) diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index daf827379..7be1944bd 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -2398,6 +2398,7 @@ bool sema_resolve_array_like_len(SemaContext *context, TypeInfo *type_info, Arra bool sema_resolve_type_info(SemaContext *context, TypeInfo *type_info, ResolveTypeKind kind); bool sema_unresolved_type_is_generic(SemaContext *context, TypeInfo *type_info); +bool use_ansi(void); void print_error_at(SourceSpan loc, const char *message, ...); void print_error_after(SourceSpan loc, const char *message, ...); void sema_note_prev_at(SourceSpan loc, const char *message, ...); @@ -2584,7 +2585,6 @@ BinaryOp binaryop_from_token(TokenType type); BinaryOp binaryop_assign_base_op(BinaryOp assign_binary_op); TokenType binaryop_to_token(BinaryOp type); - // ---- static inline function implementations. INLINE Type *type_no_optional(Type *type) diff --git a/src/compiler/diagnostics.c b/src/compiler/diagnostics.c index 2a08a406f..bf82eb010 100644 --- a/src/compiler/diagnostics.c +++ b/src/compiler/diagnostics.c @@ -75,6 +75,7 @@ static void print_error_type_at(SourceSpan location, const char *message, PrintT } else if (compiler.build.test_output || compiler.build.benchmark_output) { + bool ansi = use_ansi(); switch (print_type) { case PRINT_TYPE_ERROR: @@ -162,18 +163,40 @@ static void print_error_type_at(SourceSpan location, const char *message, PrintT } eprintf("\n"); + bool ansi = use_ansi(); if (col_location) { switch (print_type) { case PRINT_TYPE_ERROR: - eprintf("(%s:%d:%d) Error: %s\n\n", file->full_path, location.row, col_location, message); + if (ansi) + { + eprintf("(%s:%d:%d) \x1b[31;1mError\x1b[0m: %s\n\n", file->full_path, location.row, col_location, message); + } + else + { + eprintf("(%s:%d:%d) Error: %s\n\n", file->full_path, location.row, col_location, message); + } break; case PRINT_TYPE_NOTE: - eprintf("(%s:%d:%d) Note: %s\n\n", file->full_path, location.row, col_location, message); + if (ansi) + { + eprintf("(%s:%d:%d) \x1b[1mNote\x1b[0m: %s\n\n", file->full_path, location.row, col_location, message); + } + else + { + eprintf("(%s:%d:%d) Note: %s\n\n", file->full_path, location.row, col_location, message); + } break; case PRINT_TYPE_WARN: - eprintf("(%s:%d:%d) Warning: %s\n\n", file->full_path, location.row, col_location, message); + if (ansi) + { + eprintf("(%s:%d:%d) \x1b[33;1mWarning\x1b[0m: %s\n\n", file->full_path, location.row, col_location, message); + } + else + { + eprintf("(%s:%d:%d) Warning: %s\n\n", file->full_path, location.row, col_location, message); + } break; default: UNREACHABLE @@ -184,13 +207,34 @@ static void print_error_type_at(SourceSpan location, const char *message, PrintT switch (print_type) { case PRINT_TYPE_ERROR: - eprintf("(%s:%d) Error: %s\n\n", file->full_path, location.row, message); + if (ansi) + { + eprintf("(%s:%d) \x1b[31;1mError\x1b[0m: %s\n\n", file->full_path, location.row, message); + } + else + { + eprintf("(%s:%d) Error: %s\n\n", file->full_path, location.row, message); + } break; case PRINT_TYPE_NOTE: - eprintf("(%s:%d) Note: %s\n\n", file->full_path, location.row, message); + if (ansi) + { + eprintf("(%s:%d) \x1b[1mNote\x1b[0m: %s\n\n", file->full_path, location.row, message); + } + else + { + eprintf("(%s:%d) Note: %s\n\n", file->full_path, location.row, message); + } break; case PRINT_TYPE_WARN: - eprintf("(%s:%d) Warning: %s\n\n", file->full_path, location.row, message); + if (ansi) + { + eprintf("(%s:%d) \x1b[33;1mWarning\x1b[0m: %s\n\n", file->full_path, location.row, message); + } + else + { + eprintf("(%s:%d) Warning: %s\n\n", file->full_path, location.row, message); + } break; default: UNREACHABLE