From 00588bb5cd4a7ff5e2b1ded97d4459bfe6aad6eb Mon Sep 17 00:00:00 2001 From: Mark Lodato Date: Sun, 7 Mar 2010 11:52:47 -0500 Subject: grep: Colorize selected, context, and function lines Colorize non-matching text of selected lines, context lines, and function name lines. The default for all three is no color, but they can be configured using color.grep.. The first two are similar to the corresponding options in GNU grep, except that GNU grep applies the color to the entire line, not just non-matching text. Signed-off-by: Mark Lodato Signed-off-by: Junio C Hamano --- grep.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'grep.c') diff --git a/grep.c b/grep.c index 42e915d762..b641305ff6 100644 --- a/grep.c +++ b/grep.c @@ -529,6 +529,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol, const char *name, unsigned lno, char sign) { int rest = eol - bol; + char *line_color = NULL; if (opt->pre_context || opt->post_context) { if (opt->last_shown == 0) { @@ -560,12 +561,18 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol, int ch = *eol; int eflags = 0; + if (sign == ':') + line_color = opt->color_selected; + else if (sign == '-') + line_color = opt->color_context; + else if (sign == '=') + line_color = opt->color_function; *eol = '\0'; while (next_match(opt, bol, eol, ctx, &match, eflags)) { if (match.rm_so == match.rm_eo) break; - opt->output(opt, bol, match.rm_so); + output_color(opt, bol, match.rm_so, line_color); output_color(opt, bol + match.rm_so, match.rm_eo - match.rm_so, opt->color_match); @@ -575,7 +582,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol, } *eol = ch; } - opt->output(opt, bol, rest); + output_color(opt, bol, rest, line_color); opt->output(opt, "\n", 1); } -- cgit v1.3