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

Re: coloring STDERR to terminal



On Tue, 29 Jun 2004, Vincent Lefevre wrote:

> On 2004-06-29 08:43:50 -0700, Bart Schaefer wrote:

> >  coproc while read line; print '\e[91m'${(q)line}'\e[0m' > /dev/tty
> >  exec 2>&p
> 
> It doesn't work very well.

Humph.  Depends on your definition of "very well."  Everything sent to the 
standard error is printed in red, isn't it?

> Normally, if I do a Ctrl-d when there are
> running jobs, I get:
> 
> greux:~>
> zsh: you have running jobs.
> greux:~>

Which is exactly what I get even with the coproc, so there's something 
system-specific going on here (race condition resolved differently by the 
kernel process scheduler, perhaps).

> With the coprocess, I get:
> 
> greux:~>
> greux:~> zsh: you have running jobs.

If you want something fancier, have the coproc print a single byte to its
stdout every time around the read loop, and put something like

 while read -t -p -k 1; do :; done

in the precmd() function to force the main shell to synchronize with the
coproc before it prints the prompt.  However, if you produce more lines of 
output between commands than there are bytes of space in the socket buffer
you'll block the coproc and potentially deadlock everything (which is the
trouble with filtering the output of programs that don't expect to have
their output filtered, but that wasn't the question).



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