"ST" in ANSI Escape Responses is Ambiguous/Inconsistent
Thanks for filing an issue! Please answer the questions below so I can help you.
- iTerm2 version: 3.4.15
- OS version: Mojave
- Attach ~/Library/Preferences/com.googlecode.iterm2.plist here (drag-drop from finder into this window)
I know the Proprietary Escape Code documentation says:
ST means either BEL (hex code 0x07) or ESC \\.
Which is fine on input (The "Be liberal in what you accept" part of Postel's Law) but I find it frustrating that the escape sequences that are reported sometimes use ^G and sometimes use ^[\ — which seems to violate the "Be conservative in what you produce" part... And I haven't found any way of figuring out in advance which ones will use which; though it's certainly possible I just haven't looked in the right place, yet! «grin»
For example, Report Foreground/Background Colors (OSC 4) returns ^G:
^[]4;-1;rgb:fffe/ffff/ffff^G
Whereas the escape sequence that's returned from Report Cell Size uses ^[\:
^[]1337;ReportCellSize=22.0;10.0;1.0^[\
The former I can read from bash:
prompt% printf "\e]4;-1;?\a"; read -s -r -d $'\a'; cat -v <<< "$REPLY"^[]4;-1;rgb:fffe/ffff/ffff
The latter, however, is trickier, since even if I DO know which delimiter to look for, it's now two characters wide:
### If we fear the payload could ever contain a non-terminal backslash...
reportCellSize() {
local _buffer
printf "\e]1337;ReportCellSize\a" >/dev/tty;
while read -s -r -d \\ </dev/tty; do
_buffer+="$REPLY\\"
# This is the same as `[[ condition ]] && break`
# but it doesn't die under `set -e`...
! [[ $_buffer =~ $'\e\\'$ ]] || break
done
if [[ $_buffer =~ ^$'\e'\]1337\;ReportCellSize=(.*)\;(.*)\;(.*)$'\e'\\$ ]]; then
echo "height=${BASH_REMATCH[1]}"
echo "width=${BASH_REMATCH[2]}"
echo "scale=${BASH_REMATCH[3]}"
elif [[ $_buffer =~ ^$'\e'\]1337\;ReportCellSize=(.*)\;(.*)$'\e'\\$ ]]; then
echo "height=${BASH_REMATCH[1]}"
echo "width=${BASH_REMATCH[2]}"
else printf "Invalid CellSize: %q\n" "$_buffer" >&2
return 1
fi
}
Thanks for any clarification you can provide! :-D