fetch: add sixel-query & update sixel files; update kgp-query with better timeout handling

This commit is contained in:
2026-02-06 22:33:41 +01:00
parent 53b33f6422
commit 0863da0f47
11 changed files with 106 additions and 59 deletions
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail
# Ensure in a interactive terminal
[ ! -t 0 ] && exit 1
# Construct query
QUERY_CODE=$(printf "\033[c")
# Set terminal to raw mode with timeout as 0.5s
stty_orig=$(stty -g)
trap 'stty "$stty_orig"' EXIT
stty -echo -icanon min 1 time 0
printf "%s" "$QUERY_CODE" >/dev/tty
response=""
while true; do
IFS= read -r -N 1 -t 0.3 char || {
[ -z "$char" ] && break
}
response+="$char"
if [[ "$char" = "c" ]]; then
break
fi
if [ ${#response} -gt 1024 ]; then
break
fi
done
if [[ "$response" =~ $'\x1b'\[\?([0-9;]*)c ]]; then
params="${BASH_REMATCH[1]}"
IFS=';' read -ra codes <<< "$params"
for code in "${codes[@]}"; do
if [[ "$code" == "4" ]]; then
exit 0
fi
done
fi
exit 1