diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-07-30 20:16:55 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-07-30 20:16:55 -0700 |
| commit | a6d6e39f3faa83a9e9e5fdd0649da1e6a0655353 (patch) | |
| tree | f45a9942ec6e3654fbc8440151ffe6aecde3ad2f | |
| parent | ba6ee18ded5e76e852dd7eab89e6cc2b420b42d2 (diff) | |
Bugfix for trailing line numbers on plain output
| -rw-r--r-- | print.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -24,17 +24,18 @@ static const char *current_color = NULL; __attribute__((nonnull(1,2))) static inline void print_line_number(FILE *out, printer_t *pr, size_t line_number, const char *color) { - if (!pr->print_line_numbers) return; if (!pr->needs_line_number) return; - if (line_number == 0) { - if (color) fprintf(out, "\033[0;2m \033(0\x78\033(B%s", color); - else fprintf(out, " |"); - } else { - if (color) fprintf(out, "\033[0;2m%5lu\033(0\x78\033(B%s", line_number, color); - else fprintf(out, "%5lu|", line_number); + if (pr->print_line_numbers) { + if (line_number == 0) { + if (color) fprintf(out, "\033[0;2m \033(0\x78\033(B%s", color); + else fprintf(out, " |"); + } else { + if (color) fprintf(out, "\033[0;2m%5lu\033(0\x78\033(B%s", line_number, color); + else fprintf(out, "%5lu|", line_number); + } + current_color = color; } pr->needs_line_number = 0; - current_color = color; } // @@ -243,7 +244,7 @@ void print_match(FILE *out, printer_t *pr, match_t *m) const char *after_last = context_after(pr, pr->pos); print_between(out, pr, pr->pos, after_last, pr->use_color ? color_normal : NULL); // Guarantee trailing newline - if (!pr->needs_line_number || !pr->print_line_numbers) fprintf(out, "\n"); + if (!pr->needs_line_number) fprintf(out, "\n"); } if (pr->use_color) fprintf(out, "%s", color_normal); } |
