From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3032 invoked by alias); 26 Jul 2013 17:15:20 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17891 Received: (qmail 24056 invoked from network); 26 Jul 2013 17:15:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts) X-AuditID: cbfec7f4-b7fd76d0000035e1-ca-51f2ac42ed67 Date: Fri, 26 Jul 2013 18:05:04 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: print to the terminal in zle Message-id: <20130726180504.3243e220@pwslap01u.europe.root.pri> In-reply-to: <20130726134811.GA14136@chaz.gmail.com> References: <20130726134811.GA14136@chaz.gmail.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupiluLIzCtJLcpLzFFi42I5/e/4FV2nNZ8CDb595bHYcXIlowOjx6qD H5gCGKO4bFJSczLLUov07RK4Mt7eO8JY0CpRMW1bSQPjc8EuRk4OCQETiZMPulkhbDGJC/fW s3UxcnEICSxllGideIQRymGSuLj8IxtIFYuAqsSGI6vBOtgEDCWmbprNCGKLCIhKLF+xmR3E FhbQlGjovAoU5+DgFbCX+HBSBMTkBFq29x3YFCEBY4nrE+6ATeEX0Je4+vcTE8QN9hIzr5wB m8grICjxY/I9FhCbWUBLYvO2JlYIW15i85q3zBMYBWYhKZuFpGwWkrIFjMyrGEVTS5MLipPS cw31ihNzi0vz0vWS83M3MULC78sOxsXHrA4xCnAwKvHwfur7FCjEmlhWXJl7iFGCg1lJhPe6 N1CINyWxsiq1KD++qDQntfgQIxMHp1QD41zDqqT/c6Je9i99ubwuZdmv5d9tZphd9d72dMKB tiPOn770TOU/9kv93YLZGsLR6i9n2K1fu1PgzeJd61eXhh5WK71p292n+j7oz0yLGTH2OfcO Jn7bKTflS/S0n2w3z2QpHkmonP2opdB/rVx7ObewmbPJpgmX5Z3/c+uGT9+gOcv/pFP4VT0l luKMREMt5qLiRAB4K7e1HQIAAA== On Fri, 26 Jul 2013 14:48:11 +0100 Stephane Chazelas wrote: > recently, Debian broke some of my scripts using ZLE in `zsh -i` by adding: > > function zle-line-init () { > emulate -L zsh > printf '%s' ${terminfo[smkx]} > } > > To /etc/zsh/zshrc > > That smkx escape sequence is printed to stdout instead of the terminal. > > What would be the correct way to do it? > > Doing `printf > /dev/tty` would probably do it but it would be > better I think to be able to write to the fd that zsh currently > has opened to the terminal (usually 10 if it was free upon zsh > startup). > > is there a way to do that? I don't think there's a way to get the terminal file descriptor or use it for arbitrary output at the moment. I'm a bit surprised nobody ever thought of adding a mechanism for outputting terminal start and end codes before and after the line editor, but it doesn't look like anyone did, and we now have the hooks as a more general purpose mechanism. It would be possible to add an option to zle to query it and assign it to a parameter. Then you could use "print -nr -u$fd --" ('printf "%s"' is presumably an alternative to print -nr --). (You can't use >&$fd because that's reserved for file descriptors opened by the user.) Doing it this way might be enough to make it clear it's for people in white coats, i.e. this is not the normal method of terminal output. By the way, the following patch fixes a bad error message: % print -u11 blah print: bad file number: -1 True but not really the point. diff --git a/Src/builtin.c b/Src/builtin.c index 8516acd..ae2e9f6 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3792,11 +3792,11 @@ bin_print(char *name, char **args, Options ops, int func) /* -u and -p -- output to other than standard output */ if (OPT_HASARG(ops,'u') || OPT_ISSET(ops,'p')) { - int fd; + int fdarg, fd; if (OPT_ISSET(ops, 'p')) { - fd = coprocout; - if (fd < 0) { + fdarg = coprocout; + if (fdarg < 0) { zwarnnam(name, "-p: no coprocess"); return 1; } @@ -3804,13 +3804,13 @@ bin_print(char *name, char **args, Options ops, int func) char *argptr = OPT_ARG(ops,'u'), *eptr; /* Handle undocumented feature that -up worked */ if (!strcmp(argptr, "p")) { - fd = coprocout; - if (fd < 0) { + fdarg= coprocout; + if (fdarg < 0) { zwarnnam(name, "-p: no coprocess"); return 1; } } else { - fd = (int)zstrtol(argptr, &eptr, 10); + fdarg = (int)zstrtol(argptr, &eptr, 10); if (*eptr) { zwarnnam(name, "number expected after -%c: %s", 'u', argptr); @@ -3819,8 +3819,8 @@ bin_print(char *name, char **args, Options ops, int func) } } - if ((fd = dup(fd)) < 0) { - zwarnnam(name, "bad file number: %d", fd); + if ((fd = dup(fdarg)) < 0) { + zwarnnam(name, "bad file number: %d", fdarg); return 1; } if ((fout = fdopen(fd, "w")) == 0) { pws