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

Re: sending escape sequences to print in color



> I didn't know about the existence of echotc; cool.  But I prefer
> terminfo names (they're barely more mnemonic, at least).  Why doesn't
> echoti take arguments?  (That's the only thing I'd use it for--simpler
> to use the associative array for static strings.)

With the following patch, you'll be able to do
echoti setaf 4
or whatnot.

Index: Src/Modules/terminfo.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/terminfo.c,v
retrieving revision 1.19
diff -u -r1.19 terminfo.c
--- Src/Modules/terminfo.c	7 Oct 2002 11:48:08 -0000	1.19
+++ Src/Modules/terminfo.c	25 Mar 2003 05:21:51 -0000
@@ -59,8 +59,8 @@
 static int
 bin_echoti(char *name, char **argv, Options ops, int func)
 {
-    char *s, *t;
-    int num;
+    char *s, *t, *u;
+    int num, argct;
 
     s = *argv++;
     /* This depends on the termcap stuff in init.c */
@@ -92,9 +92,28 @@
 	zwarnnam(name, "no such terminfo capability: %s", s, 0);
 	return 1;
     }
-
-    tputs(t, 1, putchar);
+    /* count the number of arguments required */
+    for (argct = 0, u = t; *u; u++)
+        if (*u == '%') {
+            if (u++, (*u == 'd' || *u == '2' || *u == '3' || *u == '.' ||
+                      *u == '+'))
+                argct++;
+        }
+    /* check that the number of arguments provided is correct */
+    if (arrlen(argv) != argct) {
+        zwarnnam(name, (arrlen(argv) < argct) ? "not enough arguments" :
+                 "too many arguments", NULL, 0);
+        return 1;
+    }
+    /* output string, through the proper termcap functions */
+    if (!argct)
+        tputs(t, 1, putraw);
+    else {
+        num = (argv[1]) ? atoi(argv[1]) : atoi(*argv);
+        tputs(tparm(t, atoi(*argv)), num, putraw);
+    }
     return 0;
+
 }
 
 /**/



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