about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-12-09 17:37:01 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-12-09 17:37:01 +0000
commit02f05d746223c73981f3564ff21b324bb222e41a (patch)
tree0640e519b52d20cb446a41b5b086c762e70aca03
parent61e692400bd5c560a64f5bf299f0d6f1f0f4aa29 (diff)
downloadzsh-02f05d746223c73981f3564ff21b324bb222e41a.tar.gz
zsh-02f05d746223c73981f3564ff21b324bb222e41a.tar.xz
zsh-02f05d746223c73981f3564ff21b324bb222e41a.zip
26110: option to allow vared to open to an alternative terminal
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/zle.yo7
-rw-r--r--Src/Zle/zle_main.c19
3 files changed, 25 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 5311ee93a..857125b3a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-12-09  Peter Stephenson  <pws@csr.com>
+
+	* 26119: Doc/Zsh/zle.yo, Src/Zle/zle_main.c: option to allow vared
+	to open to an alternative terminal.
+
 2008-12-09  Clint Adams  <clint@zsh.org>
 
 	* Richard Hartmann: 26114: Completion/Unix/Command/_git: add color
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index c949e58c6..af339d37f 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -292,7 +292,8 @@ findex(vared)
 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 @@ keymap during editing.  For vi-style editing, this allows a pair of keymaps
 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)
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 60972f5c5..9106083ed 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1449,7 +1449,7 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
     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 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
 	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 @@ bin_vared(char *name, char **args, Options ops, UNUSED(int func))
     if (haso) {
 	fclose(shout);	/* close(SHTTY) */
 	shout = oshout;
-	SHTTY = -1;
+	SHTTY = oSHTTY;
     }
     if (!t || errflag) {
 	/* error in editing */
@@ -1887,7 +1896,7 @@ zle_main_entry(int cmd, va_list ap)
 
 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),
 };