From 742d83684ef593ff0e428ae444ef97bb76a94cd9 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 17 Sep 2020 01:00:22 -0700 Subject: Better printing --- file_loader.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'file_loader.c') diff --git a/file_loader.c b/file_loader.c index 7533b91..5d231d3 100644 --- a/file_loader.c +++ b/file_loader.c @@ -96,9 +96,8 @@ void fprint_line(FILE *dest, file_t *f, const char *start, const char *end, cons { size_t linenum = get_line_number(f, start); const char *line = get_line(f, linenum); - size_t charnum = 1 + (size_t)(start - line); - fprintf(dest, "\033[1m%s:%ld:%ld:\033[0m %s\n", - f->filename, linenum, charnum, msg); + size_t charnum = get_char_number(f, start); + fprintf(dest, "\033[1m%s:%ld:\033[0m %s\n", f->filename, linenum, msg); const char *eol = linenum == f->nlines ? strchr(line, '\0') : strchr(line, '\n'); if (end == NULL || end > eol) end = eol; fprintf(dest, "\033[2m% 5ld |\033[0m %.*s\033[41;30m%.*s\033[0m%.*s\n", @@ -106,10 +105,10 @@ void fprint_line(FILE *dest, file_t *f, const char *start, const char *end, cons (int)charnum - 1, line, (int)(end - &line[charnum-1]), &line[charnum-1], (int)(eol - end), end); - fprintf(dest, " "); + fprintf(dest, " \033[34;1m"); const char *p = line - 1; for (; p < start; ++p) fputc(' ', dest); if (start == end) ++end; for (; p < end; ++p) fputc('^', dest); - fputc('\n', dest); + fprintf(dest, "\033[0m\n"); } -- cgit v1.2.3