nmh-workers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nmh-workers] colorized/highlighted scan output?


From: David Levine
Subject: Re: [Nmh-workers] colorized/highlighted scan output?
Date: Sat, 03 Nov 2012 10:26:16 -0500

Here's my proposed addition, including an example
etc/scan.highlighted.  Comments?

The fmt_compile.h diff doesn't show the trivial number changes
for all following tokens.  And the Makefile.am, man page, and
test additions aren't shown here.

In fmt_scan.c, width is the parameter to scan -width, for
example.  max is the size of the fixed buffer.

I changed the ASCII ESC's in scan.highlighted to ^[ below so
as to not upset terminals or their users.

I'll be off line for the next day and will respond when I
return.

David


diff --git a/h/fmt_compile.h b/h/fmt_compile.h
+#define FT_STRLITZ     12      /* literal text with zero display width    */

diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c
+     { "zputlit",    TF_STR,   FT_STRLITZ,     0,              0 },

diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c
index 51ba24c..3818b85 100644
--- a/sbr/fmt_scan.c
+++ b/sbr/fmt_scan.c
@@ -411,2 +411,21 @@ fmt_scan (struct format *format, char *scanl, size_t max, 
int width, int *dat)
            break;
+       case FT_STRLITZ: {
+           size_t len = strlen (str);
+
+           /* Don't want to emit part of an escape sequence.  So if
+              there isn't enough room in the buffer for the entire
+              string, skip it completely. */
+           if (cp - scanl + len + 1 < max) {
+               for (sp = str; *sp; *cp++ = *sp++) continue;
+
+               /* This string doesn't count against the width.  So
+                  increase ep the same amount as cp, only if the
+                  scan buffer will always be large enough. */
+               if (ep - scanl + len + 1 < max) {
+                   ep += len;
+               }
+           }
+
+           break;
+       }
        case FT_STRFW:
@@ -978,2 +997,18 @@ fmt_scan (struct format *format, char *scanl, size_t max, 
int width, int *dat)
 #ifndef JLR
+    /* Emit any trailing sequences of zero display length. */
+    while (fmt->f_type != FT_DONE) {
+       if (fmt->f_type == FT_LS_LIT) {
+           str = fmt->f_text;
+       } else if (fmt->f_type == FT_STRLITZ) {
+           /* Don't want to emit part of an escape sequence.  So if
+              there isn't enough room in the buffer for the entire
+              string, skip it completely.  Need room for null
+              terminator, and maybe trailing newline (added below). */
+           if (cp - scanl + strlen (str) + 1 < max) {
+               for (sp = str; *sp; *cp++ = *sp++) continue;
+           }
+       }
+       fmt++;
+    }
+
     finished:;


etc/scan.highlighted:

%; scan.highlighted
%;
%; This file shows how to use ANSI escape sequences to customize scan
%; output to highlight a current message in yellow and any unseen
%; messages in cyan.  It differs from the default scan format in the
%; additional line at the beginning and the literal sequence at the end.
%;
%; To enable use of this format, add "-form scan.highlighted" to your
%; scan invocation or to your profile (~/.mh_profile), e.g.:
%;     scan: -form scan.highlighted
%;
%; You can optionally copy this file to your MH Path and modify as
%; desired.
%;
%; The mh-sequence(5) man page describes the unseen sequence.
%;
%; A more readable approach would add escape sequences to your profile, e.g.:
%;     normal: ^[[m
%;     bright-black: ^[[1;30m
%;     red: ^[[31m
%;     green: ^[[32m
%;     yellow: ^[[33m
%;     blue: ^[[34m
%;     magenta: ^[[35m
%;     cyan: ^[[36m
%;     bright-white: ^[[1;37m
%;     underlined-white: ^[[4;37m
%; To use them in the format, e.g., at the beginning:
%;     %<(cur)%(void(profile yellow))%(zputlit)%>\
%;     %<(unseen)%(void(profile cyan))%(zputlit)%>\
%; and at the end:
%;     %(void(profile normal))%(zputlit)
%;
%<(cur)%(void(lit ^[[33m))%(zputlit)%>\
%<(unseen)%(void(lit ^[[36m))%(zputlit)%>\
%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>\
%02(mon{date})/%02(mday{date})%<{date} %|*%>\
%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>\
%<(zero)%17(decode(friendly{from}))%>  \
%(decode{subject})%<{body}<<%{body}>>%>%(void(lit ^[[m))%(zputlit)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]