Add kitty terminal support

This commit is contained in:
Nikita Ivanov 2022-06-19 18:03:39 +05:00
parent 70e79d417c
commit 58e608bb98
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
4 changed files with 32 additions and 7 deletions

View File

@ -3,5 +3,3 @@
setup_fifo
send_image "$f"
exit 1

View File

@ -1,3 +1,7 @@
setup_fifo 1
printf '{"action": "remove", "identifier": "preview"}\n' > "$fifo"
if use_ueberzug; then
printf '{"action": "remove", "identifier": "preview"}\n' > "$fifo"
elif use_kitty; then
kitty +kitten icat --clear --transfer-mode file
fi

View File

@ -1,4 +1,4 @@
setup_fifo 1
# tell ctpv server to exit
printf '\0' > "$fifo"
use_ueberzug && printf '\0' > "$fifo"

View File

@ -2,6 +2,19 @@ echo_err() {
echo "$@" >&2
}
is_kitty() {
[ -n "$KITTY_PID" ]
}
use_ueberzug() {
exists ueberzug
}
use_kitty() {
use_ueberzug && return 1
is_kitty
}
fifo_open() {
# https://unix.stackexchange.com/a/522940/183147
dd oflag=nonblock conv=notrunc,nocreat count=0 of="$1" \
@ -9,6 +22,8 @@ fifo_open() {
}
setup_fifo() {
use_ueberzug || return 1
exit_code="${1:-127}"
[ -n "$fifo" ] || exit "$exit_code"
[ -e "$fifo" ] || exit "$exit_code"
@ -24,9 +39,17 @@ check_exists() {
}
send_image() {
path="$(printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g')"
printf '{ "action": "add", "identifier": "preview", "x": %d, "y": %d, "width": %d, "height": %d, "scaler": "contain", "scaling_position_x": 0.5, "scaling_position_y": 0.5, "path": "%s"}\n' "$x" "$y" "$w" "$h" "$path" > "$fifo"
return 1
if use_kitty; then
kitty +kitten icat --transfer-mode file --align left \
--place "${w}x${h}@${x}x${y}" "$1"
return 1
elif use_ueberzug; then
path="$(printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g')"
printf '{ "action": "add", "identifier": "preview", "x": %d, "y": %d, "width": %d, "height": %d, "scaler": "contain", "scaling_position_x": 0.5, "scaling_position_y": 0.5, "path": "%s"}\n' "$x" "$y" "$w" "$h" "$path" > "$fifo"
return 1
else
return 127
fi
}
convert_and_show_image() {