From d4e2fa037797c026a1b7803f1514a87792af8888 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:50:28 -0400 Subject: Refactor `show_error_on_line` This should adequately solve any issues with Unicode alignment by sidestepping the issue entirely. With this change, we make use of the built-in ANSI facilities of the terminal to underline the text. If the terminal does not support underlining, there are still the fallback bold markers at the start and end of error locations. --- src/check_stmt.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/check_stmt.cpp') diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index f2e3b0242..c369ba098 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -582,28 +582,20 @@ gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, O isize offset = show_error_on_line(e->token.pos, token_pos_end(e->token)); if (offset < 0) { if (is_type_map(e->type)) { - error_line("\tSuggestion: Did you mean? 'for key, &%.*s in ...'\n", LIT(e->token.string)); + error_line("\t\tSuggestion: Did you mean? 'for key, &%.*s in ...'\n", LIT(e->token.string)); } else { - error_line("\tSuggestion: Did you mean? 'for &%.*s in ...'\n", LIT(e->token.string)); + error_line("\t\tSuggestion: Did you mean? 'for &%.*s in ...'\n", LIT(e->token.string)); } } else { - error_line("\t"); - for (isize i = 0; i < offset-1; i++) { - error_line(" "); - } - error_line("'%.*s' is immutable, declare it as '&%.*s' to make it mutable\n", LIT(e->token.string), LIT(e->token.string)); + error_line("\t\t'%.*s' is immutable, declare it as '&%.*s' to make it mutable\n", LIT(e->token.string), LIT(e->token.string)); } } else if (e && e->flags & EntityFlag_SwitchValue) { isize offset = show_error_on_line(e->token.pos, token_pos_end(e->token)); if (offset < 0) { - error_line("\tSuggestion: Did you mean? 'switch &%.*s in ...'\n", LIT(e->token.string)); + error_line("\t\tSuggestion: Did you mean? 'switch &%.*s in ...'\n", LIT(e->token.string)); } else { - error_line("\t"); - for (isize i = 0; i < offset-1; i++) { - error_line(" "); - } - error_line("'%.*s' is immutable, declare it as '&%.*s' to make it mutable\n", LIT(e->token.string), LIT(e->token.string)); + error_line("\t\t'%.*s' is immutable, declare it as '&%.*s' to make it mutable\n", LIT(e->token.string), LIT(e->token.string)); } } } -- cgit v1.2.3