Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: coloring STDERR to terminal

On 2004-07-01 17:11:08 -0700, Bart Schaefer wrote:
> So I'm forced to conclude that there really is no way to avoid the
> race condition that you originally complained about; my first
> solution is as good as it gets. You might get close if you used
> "read -t 1 ..." to make the parent shell sleep so the kernel can
> schedule the coprocess first, but then you'd have an annoying
> 1-second delay on almost every prompt. Sorry.

I have a better solution. stderr is redirected with

  exec 2>>(while read line; do
    print '\e[91m'${(q)line}'\e[0m' > /dev/tty; done &)

as you suggested (this avoids the coprocess in the jobs table).

Now, in precmd(), adding the following line solves the problem:

  sleep 0

Of course, this won't completely avoid the race condition, but it
improves things in pratice. I assume that this forces the scheduler
to switch to another process, and in practice, the coprocess is
scheduled before precmd() is resumed.

Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% validated (X)HTML - Acorn / RISC OS / ARM, free software, YP17,
Championnat International des Jeux Mathématiques et Logiques, etc.
Work: CR INRIA - computer arithmetic / SPACES project at LORIA

Messages sorted by: Reverse Date, Date, Thread, Author