grep: color patterns in output

Coloring matches makes them easier to spot in the output.

Add two options and two parameters: color.grep (to turn coloring on
or off), color.grep.match (to set the color of matches), --color
and --no-color (to turn coloring on or off, respectively).

The output of external greps is not changed.

This patch is based on earlier ones by Nguyễn Thái Ngọc Duy and
Thiago Alves.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe
2009-03-07 13:32:32 +01:00
committed by Junio C Hamano
parent 79212772ce
commit 7e8f59d577
5 changed files with 130 additions and 12 deletions

3
grep.h
View File

@ -1,5 +1,6 @@
#ifndef GREP_H
#define GREP_H
#include "color.h"
enum grep_pat_token {
GREP_PATTERN,
@ -77,6 +78,8 @@ struct grep_opt {
unsigned relative:1;
unsigned pathname:1;
unsigned null_following_name:1;
int color;
char color_match[COLOR_MAXLEN];
int regflags;
unsigned pre_context;
unsigned post_context;