78 |
/* If nonzero, show only the part of a line matching the expression. */ |
/* If nonzero, show only the part of a line matching the expression. */ |
79 |
static int only_matching; |
static int only_matching; |
80 |
|
|
81 |
/* The color string used. The user can overwrite it using the environment |
/* The context and logic for choosing default --color screen attributes |
82 |
variable GREP_COLOR. The default is to print red. */ |
(foreground and background colors, etc.) are the following. |
83 |
static const char *grep_color = "01;31"; |
-- There are eight basic colors available, each with its own |
84 |
|
nominal luminosity to the human eye and foreground/background |
85 |
|
codes (black [0 %, 30/40], blue [11 %, 34/44], red [30 %, 31/41], |
86 |
|
magenta [41 %, 35/45], green [59 %, 32/42], cyan [70 %, 36/46], |
87 |
|
yellow [89 %, 33/43], and white [100 %, 37/47]). |
88 |
|
-- Sometimes, white as a background is actually implemented using |
89 |
|
a shade of light gray, so that a foreground white can be visible |
90 |
|
on top of it (but most often not). |
91 |
|
-- Sometimes, black as a foreground is actually implemented using |
92 |
|
a shade of dark gray, so that it can be visible on top of a |
93 |
|
background black (but most often not). |
94 |
|
-- Sometimes, more colors are available, as extensions. |
95 |
|
-- Other attributes can be selected/deselected (bold [1/22], |
96 |
|
underline [4/24], standout/inverse [7/27], blink [5/25], and |
97 |
|
invisible/hidden [8/28]). They are sometimes implemented by |
98 |
|
using colors instead of what their names imply; e.g., bold is |
99 |
|
often achieved by using brighter colors. In practice, only bold |
100 |
|
is really available to us, underline sometimes being mapped by |
101 |
|
the terminal to some strange color choice, and standout best |
102 |
|
being left for use by downstream programs such as less(1). |
103 |
|
-- We cannot assume that any of the extensions or special features |
104 |
|
are available for the purpose of choosing defaults for everyone. |
105 |
|
-- The most prevalent default terminal backgrounds are pure black |
106 |
|
and pure white, and are not necessarily the same shades of |
107 |
|
those as if they were selected explicitly with SGR sequences. |
108 |
|
Some terminals use dark or light pictures as default background, |
109 |
|
but those are covered over by an explicit selection of background |
110 |
|
color with an SGR sequence; their users will appreciate their |
111 |
|
background pictures not be covered like this, if possible. |
112 |
|
-- Some uses of colors attributes is to make some output items |
113 |
|
more understated (e.g., context lines); this cannot be achieved |
114 |
|
by changing the background color. |
115 |
|
-- For these reasons, the grep color defaults should strive not |
116 |
|
to change the background color from its default, unless it's |
117 |
|
for a short item that should be highlighted, not understated. |
118 |
|
-- The grep foreground color defaults (without an explicitly set |
119 |
|
background) should provide enough contrast to be readable on any |
120 |
|
terminal with either a black (dark) or white (light) background. |
121 |
|
This only leaves red, magenta, green, and cyan (and their bold |
122 |
|
counterparts) and possibly bold blue. */ |
123 |
|
/* The color string used for matched text. |
124 |
|
The user can overwrite it using the environment variable GREP_COLOR. */ |
125 |
|
static const char *grep_color = "01;31"; /* bold red */ |
126 |
|
|
127 |
/* Select Graphic Rendition (SGR, "\33[...m") strings. */ |
/* Select Graphic Rendition (SGR, "\33[...m") strings. */ |
128 |
/* Also Erase in Line (EL) to Right ("\33[K") by default. */ |
/* Also Erase in Line (EL) to Right ("\33[K") by default. */ |