zsh-workers
 help / color / mirror / code / Atom feed
* Re: Is this correct? Redirecting stdin/stout to implement a gdb-like "set inferior tty" in zshdb
       [not found]     ` <200812091237.mB9CbGsi024851@news01.csr.com>
@ 2008-12-09 14:10       ` Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2008-12-09 14:10 UTC (permalink / raw)
  To: Zsh Hackers' List

On Tue, 09 Dec 2008 12:37:16 +0000
Peter Stephenson <pws@csr.com> wrote:
> It would be relatively straightforward to supply vared with an option to
> use as the terminal if there was none.  However it would be messier to
> have it use the given terminal to replace any existing terminal in an
> interactive shell (it *might* work saving and restoring the FDs but it's
> a little fraught since zle not's designed to manage multiple terminals
> at once), so that option would probably be limited to use in
> non-interactive shells.

(Moved to zsh-workers.)

Well, it seems to work regardless of my worries.

Minor change to the existing behaviour:  we now check an opened device
isatty().  As previously the only device we would open was /dev/tty, this
doesn't seem like a problem.

Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.74
diff -u -r1.74 zle.yo
--- Doc/Zsh/zle.yo	17 Oct 2008 08:31:22 -0000	1.74
+++ Doc/Zsh/zle.yo	9 Dec 2008 14:06:34 -0000
@@ -292,7 +292,8 @@
 cindex(parameters, editing)
 cindex(editing parameters)
 xitem(tt(vared) [ tt(-Aache) ] [ tt(-p) var(prompt) ] [ tt(-r) var(rprompt) ])
-item(  [ -M var(main-keymap) ] [ -m var(vicmd-keymap) ] var(name))(
+xitem(  [ tt(-M) var(main-keymap) ] [ tt(-m) var(vicmd-keymap) ])
+item(  [ tt(-t) var(tty) ] var(name))(
 The value of the parameter var(name) is loaded into the edit
 buffer, and the line editor is invoked.  When the editor exits,
 var(name) is set to the string value returned by the editor.
@@ -326,6 +327,10 @@
 to override tt(viins) and tt(vicmd).  For emacs-style editing, only tt(-M)
 is normally needed but the tt(-m) option may still be used.  On exit, the
 previous keymaps will be restored.
+
+If `tt(-t) var(tty)' is given, var(tty) is the name of a terminal device
+to be used instead of the default tt(/dev/tty).  If var(tty) does not
+refer to a terminal an error is reported.
 )
 findex(zle)
 cindex(widgets, rebinding)
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.120
diff -u -r1.120 zle_main.c
--- Src/Zle/zle_main.c	12 Nov 2008 12:59:07 -0000	1.120
+++ Src/Zle/zle_main.c	9 Dec 2008 14:06:35 -0000
@@ -1449,7 +1449,7 @@
     Value v;
     Param pm = 0;
     int ifl;
-    int type = PM_SCALAR, obreaks = breaks, haso = 0;
+    int type = PM_SCALAR, obreaks = breaks, haso = 0, oSHTTY = 0;
     char *p1, *p2, *main_keymapname, *vicmd_keymapname;
     Keymap main_keymapsave = NULL, vicmd_keymapsave = NULL;
     FILE *oshout = NULL;
@@ -1558,13 +1558,22 @@
 	s = ztrdup(s);
     }
 
-    if (SHTTY == -1) {
+    if (SHTTY == -1 || OPT_ISSET(ops,'t')) {
 	/* need to open /dev/tty specially */
-	if ((SHTTY = open("/dev/tty", O_RDWR|O_NOCTTY)) == -1) {
+	oSHTTY = SHTTY;
+	if ((SHTTY = open(OPT_ISSET(ops,'t') ? OPT_ARG(ops,'t') : "/dev/tty",
+			  O_RDWR|O_NOCTTY)) == -1) {
 	    zwarnnam(name, "can't access terminal");
 	    zsfree(s);
 	    return 1;
 	}
+	if (!isatty(SHTTY)) {
+	    zwarnnam(name, "%s: not a terminal", OPT_ARG(ops,'t'));
+	    close(SHTTY);
+	    SHTTY = oSHTTY;
+	    zsfree(s);
+	    return 1;
+	}
 	oshout = shout;
 	init_shout();
 
@@ -1597,7 +1606,7 @@
     if (haso) {
 	fclose(shout);	/* close(SHTTY) */
 	shout = oshout;
-	SHTTY = -1;
+	SHTTY = oSHTTY;
     }
     if (!t || errflag) {
 	/* error in editing */
@@ -1887,7 +1896,7 @@
 
 static struct builtin bintab[] = {
     BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaM:ldDANmrsLRp", NULL),
-    BUILTIN("vared",   0, bin_vared,   1,  1, 0, "aAcehM:m:p:r:", NULL),
+    BUILTIN("vared",   0, bin_vared,   1,  1, 0, "aAcehM:m:p:r:t:", NULL),
     BUILTIN("zle",     0, bin_zle,     0, -1, 0, "aAcCDFgGIKlLmMNRU", NULL),
 };
 


-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-12-09 14:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <6cd6de210812090327o11abb9f3w2cc932515e4dbef8@mail.gmail.com>
     [not found] ` <20081209121213.GA5462@sc.homeunix.net>
     [not found]   ` <20081209121404.GB5462@sc.homeunix.net>
     [not found]     ` <200812091237.mB9CbGsi024851@news01.csr.com>
2008-12-09 14:10       ` Is this correct? Redirecting stdin/stout to implement a gdb-like "set inferior tty" in zshdb Peter Stephenson

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).