zsh-users
 help / color / mirror / code / Atom feed
From: Clint Adams <clint@zsh.org>
To: Phil Gregory <phil_g@pobox.com>
Cc: Zsh Users <zsh-users@sunsite.dk>
Subject: Re: sending escape sequences to print in color
Date: Tue, 25 Mar 2003 00:24:22 -0500	[thread overview]
Message-ID: <20030325052422.GA17570@acolyte.scowler.net> (raw)
In-Reply-To: <20030324221233.GL5531@mithrandir.aperiodic.net>

> 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;
+
 }
 
 /**/


      reply	other threads:[~2003-03-25  5:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-24 21:00 Eric Smith
2003-03-24 21:40 ` Dan Nelson
2003-03-24 21:52   ` Stephane CHAZELAS
2003-03-24 21:58     ` sending escape sequences to print in color - thanks Eric Smith
2003-03-24 22:32       ` Geoff Wing
2003-03-25  6:33       ` Stephane CHAZELAS
2003-03-25  0:03     ` sending escape sequences to print in color Thorsten Kampe
2003-03-24 22:12   ` Phil Gregory
2003-03-25  5:24     ` Clint Adams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030325052422.GA17570@acolyte.scowler.net \
    --to=clint@zsh.org \
    --cc=phil_g@pobox.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).