summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorMark Lodato <lodatom@gmail.com>2010-03-07 11:52:47 -0500
committerJunio C Hamano <gitster@pobox.com>2010-03-08 00:30:59 -0800
commit00588bb5cd4a7ff5e2b1ded97d4459bfe6aad6eb (patch)
treef3f638046ed38c6e0ad5ebc6f48a8e7973fc9e9d /grep.c
parent55f638bdc6507b3a2ce03290741f592934afaee7 (diff)
downloadgit-00588bb5cd4a7ff5e2b1ded97d4459bfe6aad6eb.tar.gz
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.<slot>. 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 <lodatom@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c11
1 files changed, 9 insertions, 2 deletions
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);
}