* Can't change stty settings with zle running
@ 2007-12-17 23:25 Stefan `Sec` Zehl
2007-12-18 10:24 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Stefan `Sec` Zehl @ 2007-12-17 23:25 UTC (permalink / raw)
To: zsh-workers
Hi,
I was trying to change a stty setting from within a signal handler:
I used this function
TRAPINFO(){
echo -n pid=$$ tty=`tty` `ttyctl`
zle && echo ", zle running" || echo ", zle NOT running"
stty -a|&grep \ erase
stty gfmt1:erase=7f
stty -a|&grep \ erase
}
When i send a sigINFO from another (important!) shell to this one, I
get the following output:
| ice:~>pid=2414 tty=/dev/ttyp1 tty is not frozen, zle running
| eol2 = <undef>; erase = ^H; erase2 = ^H; intr = ^C; kill = ^U;
| eol2 = <undef>; erase = ^?; erase2 = ^H; intr = ^C; kill = ^U;
but if I check the stty settings afterwards, they are reset back:
| ice:~>stty -a|grep \ erase
| eol2 = <undef>; erase = ^H; erase2 = ^H; intr = ^C; kill = ^U;
Ok. After some experimenting, I now understand, that this happens
because zle is running at that moment.
You can see that zle is the culprit, because if i "kill -INFO $$" from
within the same shell, it works fine:
| ice:~>kill -INFO $$
| pid=2414 tty=/dev/ttyp1 tty is not frozen, zle NOT running
| eol2 = <undef>; erase = ^H; erase2 = ^H; intr = ^C; kill = ^U;
| eol2 = <undef>; erase = ^?; erase2 = ^H; intr = ^C; kill = ^U;
| ice:~>stty -a|grep \ erase
| eol2 = <undef>; erase = ^?; erase2 = ^H; intr = ^C; kill = ^U;
On reading the zshzle manpage, i found "zle -I" which looked very
promising. But unfortunately it doesn't help:
TRAPINFO(){
zle -I
echo -n pid=$$ tty=`tty` `ttyctl`
zle && echo ", zle running" || echo ", zle NOT running"
stty -a|&grep \ erase
stty gfmt1:erase=7f
stty -a|&grep \ erase
zle -R
}
running "kill -INFO 2414" from another shell again:
| ice:~>
| pid=2414 tty=/dev/ttyp1 tty is not frozen, zle running
| eol2 = <undef>; erase = ^H; erase2 = ^H; intr = ^C; kill = ^U;
| eol2 = <undef>; erase = ^?; erase2 = ^H; intr = ^C; kill = ^U;
| ice:~>stty -a|grep \ erase
| eol2 = <undef>; erase = ^H; erase2 = ^H; intr = ^C; kill = ^U;
results in an improved display, but the stty settings are still
overwritten.
Is it possible to fix zle -I so stty changes will be honored? Or is
there another sane[1] way to do what I want?
Oh, btw. I am running:
| ice:~>echo $ZSH_VERSION
| 4.3.4
Thanks,
Sec
[1] I managed to work around this problem by defining preexec in my
signal handler and doing the stty change there, and then undefining
preexec again -- This feels very much like "the wrong way".
--
Dopeler effect: the tendency of stupid ideas to seem smarter
when they come at you rapidly.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Can't change stty settings with zle running
2007-12-17 23:25 Can't change stty settings with zle running Stefan `Sec` Zehl
@ 2007-12-18 10:24 ` Peter Stephenson
2008-02-11 22:41 ` Stefan `Sec` Zehl
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2007-12-18 10:24 UTC (permalink / raw)
To: Stefan `Sec` Zehl, zsh-workers
On Tue, 18 Dec 2007 00:25:08 +0100
Stefan `Sec` Zehl <sec@42.org> wrote:
> I was trying to change a stty setting from within a signal handler:
>...
> Ok. After some experimenting, I now understand, that this happens
> because zle is running at that moment.
That's correct. Zle sets its own terminal settings and basically ignores
the normal state from then on.
> Is it possible to fix zle -I so stty changes will be honored?
That seems pretty reasonable since you've explicitly asked to be given
control of the terminal. I've added an internal flag for this case; when
zle regains control it will save the current settings. I tried it a
little, but you probably have a more thorough test.
Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.60
diff -u -r1.60 jobs.c
--- Src/jobs.c 5 Sep 2007 16:16:17 -0000 1.60
+++ Src/jobs.c 18 Dec 2007 10:20:28 -0000
@@ -93,7 +93,7 @@
/* 1 if ttyctl -f has been executed */
/**/
-int ttyfrozen;
+mod_export int ttyfrozen;
/* Previous values of errflag and breaks if the signal handler had to
* change them. And a flag saying if it did that. */
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.101
diff -u -r1.101 zle_main.c
--- Src/Zle/zle_main.c 13 Dec 2007 21:56:18 -0000 1.101
+++ Src/Zle/zle_main.c 18 Dec 2007 10:20:30 -0000
@@ -208,10 +208,21 @@
zsetterm(void)
{
struct ttyinfo ti;
-
#if defined(FIONREAD)
int val;
+#endif
+ if (fetchttyinfo) {
+ /*
+ * User requested terminal to be returned to normal use,
+ * so remember the terminal settings if not frozen.
+ */
+ if (!ttyfrozen)
+ gettyinfo(&shttyinfo);
+ fetchttyinfo = 0;
+ }
+
+#if defined(FIONREAD)
ioctl(SHTTY, FIONREAD, (char *)&val);
if (val) {
/*
@@ -1113,6 +1124,7 @@
insmode = unset(OVERSTRIKE);
eofsent = 0;
resetneeded = 0;
+ fetchttyinfo = 0;
raw_lp = lp;
lpromptbuf = promptexpand(lp ? *lp : NULL, 1, NULL, NULL);
pmpt_attr = txtchange;
Index: Src/Zle/zle_thingy.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_thingy.c,v
retrieving revision 1.32
diff -u -r1.32 zle_thingy.c
--- Src/Zle/zle_thingy.c 29 May 2007 17:01:09 -0000 1.32
+++ Src/Zle/zle_thingy.c 18 Dec 2007 10:20:30 -0000
@@ -711,6 +711,17 @@
return ret;
}
+
+/*
+ * Flag that the user has requested the terminal be trashed
+ * for whatever use. We attempt to keep the tty settings in
+ * this mode synced with the normal (non-zle) settings unless
+ * they are frozen.
+ */
+
+/**/
+int fetchttyinfo;
+
/**/
static int
bin_zle_invalidate(UNUSED(char *name), UNUSED(char **args), UNUSED(Options ops), UNUSED(char func))
@@ -721,7 +732,18 @@
* true if a completion widget is active.
*/
if (zleactive) {
+ int wastrashed = trashedzle;
trashzle();
+ if (!wastrashed && (zlereadflags & ZLRF_NOSETTY)) {
+ /*
+ * We normally wouldn't have restored the terminal
+ * in this case, but as it's at user request we do
+ * so (hence the apparently illogical sense of the
+ * second part of the test).
+ */
+ settyinfo(&shttyinfo);
+ }
+ fetchttyinfo = 1;
return 0;
} else
return 1;
--
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] 3+ messages in thread
* Re: Can't change stty settings with zle running
2007-12-18 10:24 ` Peter Stephenson
@ 2008-02-11 22:41 ` Stefan `Sec` Zehl
0 siblings, 0 replies; 3+ messages in thread
From: Stefan `Sec` Zehl @ 2008-02-11 22:41 UTC (permalink / raw)
To: Peter Stephenson; +Cc: zsh-workers
Hi,
On Tue, Dec 18, 2007 at 10:24 +0000, Peter Stephenson wrote:
> Stefan `Sec` Zehl <sec@42.org> wrote:
> > I was trying to change a stty setting from within a signal handler:
> >...
> > Is it possible to fix zle -I so stty changes will be honored?
>
> That seems pretty reasonable since you've explicitly asked to be given
> control of the terminal. I've added an internal flag for this case; when
> zle regains control it will save the current settings. I tried it a
> little, but you probably have a more thorough test.
Thanks for your patch. I just wanted to report that I've been running
with it for over a Month now, and it works perfectly.
Thanks,
Sec
--
It's actually quite difficult to be extreme,
you have to be kind of stupid
limited in the information that you've been fed
and possibly religuous. -- Joi Ito
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-02-11 22:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-17 23:25 Can't change stty settings with zle running Stefan `Sec` Zehl
2007-12-18 10:24 ` Peter Stephenson
2008-02-11 22:41 ` Stefan `Sec` Zehl
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).