diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-05-19 21:12:41 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-05-19 21:12:41 -0700 |
| commit | 6ff7a6753032bc41098042258096bde73ed4bd1c (patch) | |
| tree | fe34d02a5815d0e047f859c72b8296d8eb2e9566 | |
| parent | 10532ca614ae279125aec368d591f94383c5bcd5 (diff) | |
When printing with zero context, put each match on its own line
| -rw-r--r-- | print.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -377,6 +377,13 @@ void print_match(FILE *out, printer_t *pr, match_t *m) if (m) { const char *before_m = context_before(pr, m->start); if (!first) { + // When not printing context lines, print each match on its own + // line instead of jamming them all together: + if (pr->context_lines == 0 && (!pr->needs_line_number || !pr->print_line_numbers)) { + fprintf(out, "\n"); + pr->needs_line_number = 1; + } + const char *after_last = context_after(pr, pr->pos); if (after_last >= before_m) { // Overlapping ranges: @@ -395,7 +402,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) fprintf(out, "\n"); + if (!pr->needs_line_number || !pr->print_line_numbers) fprintf(out, "\n"); } if (pr->use_color) fprintf(out, "%s", color_normal); } |
