aboutsummaryrefslogtreecommitdiff
path: root/print.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-05-19 21:12:41 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-05-19 21:12:41 -0700
commit6ff7a6753032bc41098042258096bde73ed4bd1c (patch)
treefe34d02a5815d0e047f859c72b8296d8eb2e9566 /print.c
parent10532ca614ae279125aec368d591f94383c5bcd5 (diff)
When printing with zero context, put each match on its own line
Diffstat (limited to 'print.c')
-rw-r--r--print.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/print.c b/print.c
index a9a2f57..9e0897c 100644
--- a/print.c
+++ b/print.c
@@ -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);
}