[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Support for match highlighting on certain deficient terminals wi
From: |
Nix |
Subject: |
[PATCH] Support for match highlighting on certain deficient terminals without CSI[0m |
Date: |
10 Dec 2002 13:47:10 +0000 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Military Intelligence) |
I'm cursed to use Intelliterm 6.0a at work, which supports all the xterm
colour-selection codes, *except* for CSI[0m, CSI[39m and CSI[49m (the
colour-resetting ones); you have to explicitly set the colours back to
the pre-existing ones when a match is over (and to work out the
pre-existing colours, you have to use, um, guesswork.)
This makes GNU grep's colour-selection code a bit annoyed.
Here's a patch that makes the disable-highlight code customizable just
as enable-highlight is, for any other unfortunates cursed with
substandard terminals:
2002-12-10 Nix <address@hidden>
* src/grep.c (grep_uncolor): New variable...
* src/grep.c (main): ... set it, from GREP_UNCOLOR...
* src/grep.c (prline): ... and emit it at match-unhighlight time.
2002-12-10 Nix <address@hidden>
* doc/grep.texi (Invoking): Document GREP_UNCOLOR.
doc/grep.texi | 15 ++++++++++++---
src/grep.c | 18 +++++++++++++-----
2 files changed, 25 insertions(+), 8 deletions(-)
diff -durN 2.5-orig/doc/grep.texi 2.5/doc/grep.texi
--- 2.5-orig/doc/grep.texi Tue Jan 22 13:20:04 2002
+++ 2.5/doc/grep.texi Mon Dec 9 14:02:22 2002
@@ -265,7 +265,9 @@
@itemx address@hidden
@opindex --colour
@cindex highlight, color, colour
-The matching string is surrounded by the marker specify in @var{GREP_COLOR}.
+The matching string is preceded by the marker specified in @var{GREP_COLOR},
+and followed by that specified in @var{GREP_UNCOLOR} (if any) or by a
+conventional VT-terminal `return to normal' code otherwise.
@var{WHEN} may be `never', `always', or `auto'.
@item address@hidden
@@ -575,8 +577,15 @@
@item GREP_COLOR
@vindex GREP_COLOR
@cindex highlight markers
-This variable specifies the surrounding markers use to highlight the matching
-text. The default is control ascii red.
+This variable specifies the marker used to highlight matching text. The
+default is control ascii red.
+
address@hidden GREP_UNCOLOR
address@hidden GREP_UNCOLOR
address@hidden highlight markers
+This variable specifies the marker used to return to normal after a
+region of matching text has passed. The default is a VT-terminal code
+that does the job on such terminals.
@item LC_ALL
@itemx LC_COLLATE
diff -durN 2.5-orig/src/grep.c 2.5/src/grep.c
--- 2.5-orig/src/grep.c Wed Mar 13 14:49:52 2002
+++ 2.5/src/grep.c Mon Dec 9 14:05:50 2002
@@ -66,7 +66,7 @@
/* If nonzero, use mmap if possible. */
static int mmap_option;
-/* If nonzero, use grep_color marker. */
+/* If nonzero, use grep_color and grep_uncolor markers. */
static int color_option;
/* If nonzero, show only the part of a line matching the expression. */
@@ -76,6 +76,10 @@
variable GREP_COLOR. The default is to print red. */
static const char *grep_color = "01;31";
+/* The `color' to use to reset the screen colors to what they were before. The
+ user can overwrite it using the environment variable GREP_UNCOLOR. */
+static const char *grep_uncolor = "00";
+
static struct exclude *excluded_patterns;
static struct exclude *included_patterns;
/* Short options. */
@@ -543,7 +547,7 @@
printf("\33[%sm", grep_color);
fwrite(b, sizeof (char), match_size, stdout);
if(color_option)
- fputs("\33[00m", stdout);
+ printf("\33[%sm", grep_uncolor);
fputs("\n", stdout);
beg = b + match_size;
}
@@ -574,7 +578,7 @@
fwrite (beg, sizeof (char), match_offset, stdout);
printf ("\33[%sm", grep_color);
fwrite (b, sizeof (char), match_size, stdout);
- fputs ("\33[00m", stdout);
+ printf ("\33[%sm", grep_uncolor);
beg = b + match_size;
ibeg = ibeg + match_offset + match_size;
}
@@ -593,7 +597,7 @@
fwrite (beg, sizeof (char), match_offset, stdout);
printf ("\33[%sm", grep_color);
fwrite (b, sizeof (char), match_size, stdout);
- fputs ("\33[00m", stdout);
+ printf ("\33[%sm", grep_uncolor);
beg = b + match_size;
}
}
@@ -1643,9 +1647,13 @@
if (color_option)
{
- char *userval = getenv ("GREP_COLOR");
+ char *userval;
+ userval = getenv ("GREP_COLOR");
if (userval != NULL && *userval != '\0')
grep_color = userval;
+ userval = getenv ("GREP_UNCOLOR");
+ if (userval != NULL && *userval != '\0')
+ grep_uncolor = userval;
}
if (! matcher)
--
`Ah, but don't you feel the jackboot of state oppression whenever you have
to deal with the uniformed storm-troopers of government bureaucracy, viz.
the bus company ticket inspectors?
Damn you for a Stalinist stooge!' --- Charlie Stross
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Support for match highlighting on certain deficient terminals without CSI[0m,
Nix <=