summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 55f638b)
raw | patch | inline | side by side (parent: 55f638b)
author | Mark Lodato <lodatom@gmail.com> | |
Sun, 7 Mar 2010 16:52:47 +0000 (11:52 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 8 Mar 2010 08:30:59 +0000 (00:30 -0800) |
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>
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>
Documentation/config.txt | patch | blob | history | |
builtin-grep.c | patch | blob | history | |
grep.c | patch | blob | history | |
grep.h | patch | blob | history |
index d6e4a3e0cce71e78ec3bfc3f7753d240be265fb2..88e1d49d6e91e289f5caf58254d713fd8c523bf0 100644 (file)
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
part of the line to use the specified color, and is one of
+
--
+`context`;;
+ non-matching text in context lines (when using `-A`, `-B`, or `-C`)
`filename`;;
filename prefix (when not using `-h`)
+`function`;;
+ function name lines (when using `-p`)
`linenumber`;;
line number prefix (when using `-n`)
`match`;;
matching text
+`selected`;;
+ non-matching text in selected lines
`separator`;;
separators between fields on a line (`:`, `-`, and `=`)
and between hunks (`--`)
diff --git a/builtin-grep.c b/builtin-grep.c
index 09c2f4913b24436489f6647b95368ee070554b14..d455176f78b929435207c21c4eabac5eabde3a63 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
if (!strcmp(var, "color.grep"))
opt->color = git_config_colorbool(var, value, -1);
+ else if (!strcmp(var, "color.grep.context"))
+ color = opt->color_context;
else if (!strcmp(var, "color.grep.filename"))
color = opt->color_filename;
+ else if (!strcmp(var, "color.grep.function"))
+ color = opt->color_function;
else if (!strcmp(var, "color.grep.linenumber"))
color = opt->color_lineno;
else if (!strcmp(var, "color.grep.match"))
color = opt->color_match;
+ else if (!strcmp(var, "color.grep.selected"))
+ color = opt->color_selected;
else if (!strcmp(var, "color.grep.separator"))
color = opt->color_sep;
else
opt.regflags = REG_NEWLINE;
opt.max_depth = -1;
+ strcpy(opt.color_context, "");
strcpy(opt.color_filename, "");
+ strcpy(opt.color_function, "");
strcpy(opt.color_lineno, "");
strcpy(opt.color_match, GIT_COLOR_BOLD_RED);
+ strcpy(opt.color_selected, "");
strcpy(opt.color_sep, GIT_COLOR_CYAN);
opt.color = -1;
git_config(grep_config, &opt);
index 42e915d762d82cdb81b5cb5028eee04b707a0aa5..b641305ff6e9a05b20d92e9c0274004625bd7f28 100644 (file)
--- a/grep.c
+++ b/grep.c
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) {
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);
}
*eol = ch;
}
- opt->output(opt, bol, rest);
+ output_color(opt, bol, rest, line_color);
opt->output(opt, "\n", 1);
}
index 36919ee2175849c8dce1739e72f3e477812a53bc..2c4bdaca823c71f7628fb7626b7222e69db332a8 100644 (file)
--- a/grep.h
+++ b/grep.h
int color;
int max_depth;
int funcname;
+ char color_context[COLOR_MAXLEN];
char color_filename[COLOR_MAXLEN];
+ char color_function[COLOR_MAXLEN];
char color_lineno[COLOR_MAXLEN];
char color_match[COLOR_MAXLEN];
+ char color_selected[COLOR_MAXLEN];
char color_sep[COLOR_MAXLEN];
int regflags;
unsigned pre_context;