Closed DanielDewberry closed 2 years ago
@DanielDewberry
Sorry but this PR completely missed the point.
This patch would cause xxd
to print the bytes that echo
outputs. That would be pointless, as it wouldn't tell you anything about the status of the terminal.
The objective is to send a control sequence to the terminal, which is a request that causes the terminal to reply with a control sequence (as if it had been typed) and then for xxd
to read those bytes and display them in a printable form to make them easier to understand.
You then need to press ctrl-D to finish the input to xxd, one or twice until you get the shell prompt back. (You will probably need to press it twice, but if one suffices to get your shell prompt back, you don't want to press it again, because that will log you out.) If the terminal does not respond to the enquiry sequence, nothing will be printed, and you still need to press ctrl-D until your shell prompt returns.
A more sophisticated version would be to use the read
built-in command, with a time limit:
IFS= read -s -p $'\e[48:2:1:2:3m\eP$qm\e\\' -N50 -t1 reply
printf %q\\n "$reply"
printf %s "$reply" | xxd
That's
IFS=
temporarily set the shell variable IFS
to empty, just for the duration of the read
command, which causes read
not tot split or strip whitespaceread
(a built-in command)-s
turn off echo-p
send a "prompt" (in this case, the color query command)$'...'
interpret the quoted string like printf
or echo -e
-N50
read up to 50 bytes-t1
wait up to 1 secondreply
(the name of the variable where the input will be stored)@kurahaupo Thank you for your thoughtful reply. I accept what you have said and recognise my error.
The inclusion of this line 00000000: 1b50 3124 7234 383a 323a 313a 323a 336d .P1$r48:2:1:2:3m
is what confused me as I had executed the command ((echo -e '\e[48:2:1:2:3m\eP$qm\e\\' ; xxd)
) in Konsole which waited for input on stdin and yielded no further information from xxd upon sending the the CTRL-D signal.
(echo -e '\e[48:2:1:2:3m\eP$qm\e\\' ; xxd)
2:1:2:3m
I then ran it piped into xxd
which (misleadingly resembled the stated behaviour) and then ran the command without xxd
which yielded the same output, without the hang.
(echo -e '\e[48:2:1:2:3m\eP$qm\e\\' )
2:1:2:3m
It was not until moments ago that I loaded https://onlinegdb.com and executed the command with xxd that i received similar output to the stated behaviour upon pressing CTRL-D
^[P1$r0m^[\0000000: 1b50 3124 7230 6d1b 5c .P1$r0m.\
Thank you for your time and thorough explanation
This example prints the escape sequence to standard out, then launches
xxd
which waits for input on standard input.Change the
;
to a pipe send the escape sequence intoxxd
Example output: