zsh-users
 help / color / mirror / code / Atom feed
* Advanced scripting Q: notification to tty
@ 2004-12-24 18:09 kynn
  2005-01-03 16:37 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: kynn @ 2004-12-24 18:09 UTC (permalink / raw)
  To: zsh-users



I want to implement a notification by a function to the terminal
controlling an interactive zsh

For this implementation I'd like to follow the "asynchronous" approach
that zsh uses by default to notify the user when background jobs
finish.  By "asynchronous" I mean that the notification does not wait
for the user to hit the return key to show up on the screen; the shell
prints the notification immediately, and simply re-creates the input
line that was interrupted by the notification.  The simplest example
of this behavior is barely noticeable:

[25] 13:02 % sleep 1 &                                              ~/local/tmp
[1] 29680
[26] 13:03 %                                                        ~/local/tmp
[1]  + done       sleep 1
[26] 13:03 %                                                        ~/local/tmp

Here the notification arrived when the user was not typing anything,
so the shell merely re-produces the left and right prompts (this
*wouldn't* happen after a simple

  echo "[1] +done        sleep 1"

statement).  A more obvious example:

[26] 13:03 % sleep 10 &                                             ~/local/tmp
[1] 29686
[27] 13:04 % echo '                                                 ~/local/tmp
quote> Taking my
quote> sweet time h
[1]  + done       sleep 10 
quote> sweet time here...'

Taking my
sweet time here...
[28] 13:05 %                                                        ~/local/tmp

Here the shell's notification arrives while the user is in the middle
of typing a multi-line command, so the shell re-creates the
interrupted line for the user.  *Very nicely done*.

Does zsh provide any facilities for programmers to achieve this effect
in shell scripts?

Absent this, what is the best way to implement "synchronous"
notification (i.e. one that happens only after the user hits the Enter
key) in zsh scripts?

Thanks!

kj


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Advanced scripting Q: notification to tty
  2004-12-24 18:09 Advanced scripting Q: notification to tty kynn
@ 2005-01-03 16:37 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2005-01-03 16:37 UTC (permalink / raw)
  To: kynn; +Cc: zsh-users

On Fri, 24 Dec 2004 kynn@panix.com wrote:

> I want to implement a notification by a function to the terminal
> controlling an interactive zsh
> 
> [...] the shell's notification arrives while the user is in the middle
> of typing a multi-line command, so the shell re-creates the
> interrupted line for the user.  *Very nicely done*.
> 
> Does zsh provide any facilities for programmers to achieve this effect
> in shell scripts?

Yes, look at the "zle" command's -F option which allows you to install an
asynchronous I/O handler function in the line editor.  See also "zle -I".

> Absent this, what is the best way to implement "synchronous" 
> notification (i.e. one that happens only after the user hits the Enter 
> key) in zsh scripts?

Have the notifier write to a named pipe (or use the coproc descriptor) and 
examine that for available input in the user-definable precmd function.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-01-03 16:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-24 18:09 Advanced scripting Q: notification to tty kynn
2005-01-03 16:37 ` Bart Schaefer

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