Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: allow colours in WATCHFMT with %F/%K



Given that WATCHFMT supports the usual %S, %B and %U, it seems like an
omission to not also allow %F and %K.

And as it is now in a module, I don't feel guilty for adding bloat to a
little used feature. The shout variable appears to be null when log is
redirected to a pipe and in other cases it was separately buffered so I
needed to make set_colour_attribute use putraw instead of putshout for
the colour sequences. You can't use %4F forms, only %F{4}.

Oliver

diff --git a/Doc/Zsh/mod_watch.yo b/Doc/Zsh/mod_watch.yo
index 4eea89e23..1080d7f62 100644
--- a/Doc/Zsh/mod_watch.yo
+++ b/Doc/Zsh/mod_watch.yo
@@ -65,6 +65,14 @@ The `tt(%m)' and `tt(%M)' escapes will work only if there is a host name
 field in the utmp on your machine.  Otherwise they are
 treated as ordinary strings.
 )
+item(tt(%F) LPAR()tt(%f)RPAR())(
+Start (stop) using a different foreground colour. The colour is given
+in braces following the tt(%F).
+)
+item(tt(%K) LPAR()tt(%k)RPAR())(
+Start (stop) using a different background colour. The colour is given
+in braces following the tt(%K).
+)
 item(tt(%S) LPAR()tt(%s)RPAR())(
 Start (stop) standout mode.
 )
diff --git a/Src/Modules/watch.c b/Src/Modules/watch.c
index 95d591a67..d45c3cf3d 100644
--- a/Src/Modules/watch.c
+++ b/Src/Modules/watch.c
@@ -246,6 +246,7 @@ watchlog2(int inout, WATCH_STRUCT_UTMP *u, char *fmt, int prnt, int fini)
     struct tm *tm;
     char *fm2;
     int len;
+    zattr atr;
 # ifdef WATCH_UTMP_UT_HOST
     char *p;
     int i;
@@ -347,6 +348,40 @@ watchlog2(int inout, WATCH_STRUCT_UTMP *u, char *fmt, int prnt, int fini)
 		case '%':
 		    putchar('%');
 		    break;
+		case 'F':
+		    if (*fmt == '{') {
+			fmt++;
+			atr = match_colour((const char**)&fmt, 1, 0);
+			if (*fmt == '}')
+			    fmt++;
+			if (!(atr & (TXT_ERROR | TXTNOFGCOLOUR))) {
+			    txtunset(TXT_ATTR_FG_COL_MASK);
+			    txtset(atr & TXT_ATTR_FG_ON_MASK);
+			    set_colour_attribute(atr, COL_SEQ_FG, TSC_RAW);
+			}
+		    }
+		    break;
+		case 'f':
+		    txtunset(TXT_ATTR_FG_ON_MASK);
+		    set_colour_attribute(TXTNOFGCOLOUR, COL_SEQ_FG, TSC_RAW);
+		    break;
+		case 'K':
+		    if (*fmt == '{') {
+			fmt++;
+			atr = match_colour((const char**)&fmt, 0, 0);
+			if (*fmt == '}')
+			    fmt++;
+			if (!(atr & (TXT_ERROR | TXTNOBGCOLOUR))) {
+			    txtunset(TXT_ATTR_BG_COL_MASK);
+			    txtset(atr & TXT_ATTR_BG_ON_MASK);
+			    set_colour_attribute(atr, COL_SEQ_BG, TSC_RAW);
+			}
+		    }
+		    break;
+		case 'k':
+		    txtunset(TXT_ATTR_BG_ON_MASK);
+		    set_colour_attribute(TXTNOBGCOLOUR, COL_SEQ_BG, TSC_RAW);
+		    break;
 		case 'S':
 		    txtset(TXTSTANDOUT);
 		    tsetcap(TCSTANDOUTBEG, TSC_RAW);
diff --git a/Src/prompt.c b/Src/prompt.c
index 6943eabc3..d6b378539 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -1045,9 +1045,9 @@ tsetcap(int cap, int flags)
 	    if (txtisset(TXTUNDERLINE))
 		tsetcap(TCUNDERLINEBEG, flags);
 	    if (txtisset(TXTFGCOLOUR))
-		set_colour_attribute(txtattrmask, COL_SEQ_FG, TSC_PROMPT);
+		set_colour_attribute(txtattrmask, COL_SEQ_FG, flags);
 	    if (txtisset(TXTBGCOLOUR))
-		set_colour_attribute(txtattrmask, COL_SEQ_BG, TSC_PROMPT);
+		set_colour_attribute(txtattrmask, COL_SEQ_BG, flags);
 	}
     }
 }
@@ -2062,7 +2062,8 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
 		    *bv->bp++ = Outpar;
 		}
 	    } else {
-		tputs(tgoto(tcstr[tc], colour, colour), 1, putshout);
+		tputs(tgoto(tcstr[tc], colour, colour), 1,
+			(flags & TSC_RAW) ? putraw : putshout);
 	    }
 	    /* That worked. */
 	    return;
@@ -2121,7 +2122,7 @@ set_colour_attribute(zattr atr, int fg_bg, int flags)
 	    *bv->bp++ = Outpar;
 	}
     } else
-	tputs(colseq_buf, 1, putshout);
+	tputs(colseq_buf, 1, (flags & TSC_RAW) ? putraw : putshout);
 
     if (do_free)
 	free_colour_buffer();




Messages sorted by: Reverse Date, Date, Thread, Author