zsh-users
 help / color / mirror / code / Atom feed
* strange interaction between read command and pipe to less from function
@ 2023-03-26 14:33 Jim
  2023-03-26 14:55 ` Roman Perepelitsa
  0 siblings, 1 reply; 7+ messages in thread
From: Jim @ 2023-03-26 14:33 UTC (permalink / raw)
  To: zsh


[-- Attachment #1.1: Type: text/plain, Size: 1150 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 1667 bytes --]

[-- Attachment #2: cvt_256_colors_2_rgb_hex_fmt.txt --]
[-- Type: text/plain, Size: 759 bytes --]

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 :

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

end of thread, other threads:[~2023-03-26 23:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-26 14:33 strange interaction between read command and pipe to less from function Jim
2023-03-26 14:55 ` Roman Perepelitsa
2023-03-26 15:28   ` Jim
2023-03-26 15:49     ` Roman Perepelitsa
2023-03-26 17:04       ` Jim
2023-03-26 17:23         ` Roman Perepelitsa
2023-03-26 23:50           ` Lawrence Velázquez

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