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

Re: coloring STDERR to terminal

On Thu, 1 Jul 2004, Vincent Lefevre wrote:

> I don't understand why it will block. The line you gave was:
>   while read -t -p -k 1; do :; done

Ah.  You're right; I had only a half-formed thought, there.

I originally wrote (before sending my message, i.e. during the editing 
process) "read -p -k 1" (no loop), implying always read one byte from the 
coprocess.  But in re-reading I realized that blocks forever when there is 
no stderr for the coproc to colorize.  So I changed it to the "while" 
loop, which would do nothing if the coprocess produced no output, and read 
the byte otherwise.  But I failed to notice that this also means it does 
nothing if the coproc has not written the byte *yet*, which is what you 
were pointing out.

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.

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