<<< Date Index >>>     <<< Thread Index >>>

Re: Multi-Line Color Highlighting



Hi Gary,

Thanks very much for your informative reply.  I'll attempt a similar
strategy.

-- 
Mun


On Mon, Feb 04, 2008 at 04:55 PM PST, Gary Johnson wrote:
GJ> On 2008-02-03, Mun Johl <Mun.Johl@xxxxxxxxxx> wrote:
GJ> > (Sorry, I didn't provide a sufficient subject on the original post.)
GJ> > 
GJ> > Hi,
GJ> > 
GJ> > I was wondering if there is a way to highlight a mulit-line regex in the
GJ> > body of a message?  I am trying to use "color body ..." to highlight a
GJ> > multi-line description in our bug tracking tool but I'm not certain if
GJ> > mutt's highlighting feature even supports such an option.  And I didn't
GJ> > see anything one way or the other in the manual.
GJ> 
GJ> What I have done to achieve this is to create a display_filter using 
GJ> Perl to add ANSI color escape sequences around the text I wanted to 
GJ> highlight.  I also add "set allow_ansi" in my muttrc so that mutt 
GJ> will pass these escape sequences through to the terminal.  I use 
GJ> message-hooks to enable the various display_filters.  Here's part of 
GJ> one display_filter.
GJ> 
GJ>    perl -00 -pe 's/^(IN THIS ISSUE)/\e[1m\1\e[0m/s;
GJ>                  s/^(LOCAL NEWS)/\e[1m\1\e[0m/s;
GJ>                  if (m/^((\(.*\))?[^a-z]*?[a-z]?[^a-z]*?)(\s--\s.*)/s) {
GJ>                      $heading = $1;
GJ>                      $part2 = $3;                  # Save this for printing 
later.
GJ>                      $heading =~ s/^/\e[1m/s;      # Turn on highlighting 
at start of heading.
GJ>                      $heading =~ s/$/\e[0m/s;      # Turn off highlighting 
at end of heading.
GJ>                      $heading =~ s/\n/\n\e[1m/gs;  # Turn on highlighting 
at start of every line within heading.
GJ>                      $_ = $heading . $part2;
GJ>                  }'
GJ> 
GJ> This highlights a few section headings in a newsletter, including 
GJ> in-line headings from the start of a paragraph to the first 
GJ> occurrence of "--", provided there is no more than one lower-case 
GJ> letter in that interval.
GJ> 
GJ> I wrote this when I had built mutt with slang.  It seemed at the 
GJ> time that either mutt or slang turned off highlighting at the end of 
GJ> every line, so I had to turn it on at the start of every line within 
GJ> the highlighted region.  I now use ncurses instead of slang, and the 
GJ> script still works, but I haven't checked to see whether turning on 
GJ> highlighting at the start of every highlighted line is still 
GJ> necessary.
GJ> 
GJ> HTH,
GJ> Gary