diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-10-02 01:37:05 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-10-02 01:37:05 -0400 |
| commit | 0a4283b38ba40242f8f9302a63e8c4d664a50799 (patch) | |
| tree | f3f9fadc7c5683197d0b09abbfd8c58b779db8e9 /src/errmsg.cpp | |
| parent | b3f3db46bec83bd467f4e0759ab58965aa3a8459 (diff) | |
| download | zig-0a4283b38ba40242f8f9302a63e8c4d664a50799.tar.gz zig-0a4283b38ba40242f8f9302a63e8c4d664a50799.zip | |
support terminal colors for cmd.exe and msys pty
See #302
Diffstat (limited to 'src/errmsg.cpp')
| -rw-r--r-- | src/errmsg.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/errmsg.cpp b/src/errmsg.cpp index 91a12fda4e..bef4d7548d 100644 --- a/src/errmsg.cpp +++ b/src/errmsg.cpp @@ -10,12 +10,6 @@ #include <stdio.h> -#define RED "\x1b[31;1m" -#define GREEN "\x1b[32;1m" -#define CYAN "\x1b[36;1m" -#define WHITE "\x1b[37;1m" -#define RESET "\x1b[0m" - enum ErrType { ErrTypeError, ErrTypeNote, @@ -27,12 +21,26 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) size_t col = err->column_start + 1; const char *text = buf_ptr(err->msg); - - if (color == ErrColorOn || (color == ErrColorAuto && os_stderr_tty())) { + bool is_tty = os_stderr_tty(); + if (color == ErrColorOn || (color == ErrColorAuto && is_tty)) { if (err_type == ErrTypeError) { - fprintf(stderr, WHITE "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": " RED "error:" WHITE " %s" RESET "\n", path, line, col, text); + os_stderr_set_color(TermColorWhite); + fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", path, line, col); + os_stderr_set_color(TermColorRed); + fprintf(stderr, "error:"); + os_stderr_set_color(TermColorWhite); + fprintf(stderr, " %s", text); + os_stderr_set_color(TermColorReset); + fprintf(stderr, "\n"); } else if (err_type == ErrTypeNote) { - fprintf(stderr, WHITE "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": " CYAN "note:" WHITE " %s" RESET "\n", path, line, col, text); + os_stderr_set_color(TermColorWhite); + fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", path, line, col); + os_stderr_set_color(TermColorCyan); + fprintf(stderr, "note:"); + os_stderr_set_color(TermColorWhite); + fprintf(stderr, " %s", text); + os_stderr_set_color(TermColorReset); + fprintf(stderr, "\n"); } else { zig_unreachable(); } @@ -41,7 +49,10 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) for (size_t i = 0; i < err->column_start; i += 1) { fprintf(stderr, " "); } - fprintf(stderr, GREEN "^" RESET "\n"); + os_stderr_set_color(TermColorGreen); + fprintf(stderr, "^"); + os_stderr_set_color(TermColorReset); + fprintf(stderr, "\n"); } else { if (err_type == ErrTypeError) { fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": error: %s\n", path, line, col, text); |
