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

strange interaction between read command and pipe to less from function



Hi everyone,

I'm at a loss trying to figure out what is going on with a function I am testing.
It has the following read statement which is part of a loop:

for N ({0..255}) {
  read -s -t1 -d $'\a' $'c?\e]4;'${N}$';?\a' && XC+=("$N ${c##*;}")
}

This works just fine in retrieving the hex color codes in both xterm and xfce4-terminal.

The issue is when the output of my function is piped to less.  The keys do not respond
correctly.  Where 'space' would normally page the output, or 'q' would quit less, I now
have to follow the keystroke(space, q, gg ...) with the 'enter' key to have the action take
place.

Commenting out the read statement and less acts normally from output I generated
to test with or without the read statement.

I attached the function file with an added '.txt' extension to name(FYI).

Any thoughts on what is happening would be appreciated. The read statement was
taken from something I found on one of the 'Stack' sites if I remember correctly.

I guess I could be using the read statement incorrectly, but I don't know what it
could be.

ZSH_PATCHLEVEL:  zsh-5.9-0-g73d3173

Thanks in advance, and regards,

Jim Murphy

emulate -L zsh -o extendedglob
# Function:  cvt_256_colors_2_rgb_hex_fmt
local     E N c
local -a  T S XC NRGB
local -aU RGB
for N ({0..255}) {
  :
  read -s -t1 -d $'\a' $'c?\e]4;'${N}$';?\a' && XC+=("$N ${c##*;}")
}
for E ($XC) {
  S=(${(z)E}) ; T=(${(s./.)S[2]#*:})
  NRGB+=("${(l.3..0.)S[1]} ${${T[1]}[1,2]}${${T[2]}[1,2]}${${T[3]}[1,2]}")
  RGB+=("${${T[1]}[1,2]}${${T[2]}[1,2]}${${T[3]}[1,2]}")
}
#print -- "XC: $#XC   NRGB: $#NRGB   RGB: $#RGB"
#print -- "$XC[1]   $XC[256]"
#print -- "$NRGB[1]   $NRGB[256]"
#print -- "$RGB[1]   $RGB[256]"
#print -l -- $XC
#print -l -- $NRGB
#print -l -- $RGB
# Next line is just output to see if read command is doing something strange
for E (${(ok)parameters}) print -- $E
# vim: ts=2 sw=2 sts=2 sta ai et ft=zsh :


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