summaryrefslogtreecommitdiff
path: root/home/.selfconfigs/imv/imv-ctl
blob: a55e5e89a55bb913ec030058c2760b2ca78bd282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash -eu

if [ $# == 0 ] || ! [[ "$1" =~ ^[0-9]+$ ]]; then
	echo usage: imv-ctl [IMV PID]
	exit
fi

trap 'tput sgr0; tput cnorm; tput rmcup || clear; exit 0' SIGINT

tput smcup; tput civis
tput clear

cat << EOF
Current pid: $1
----------------------
Controls:
p	- quit
left	- previous image
right	- next image
f	- toggle fullscreen
i	- zoom in
k	- zoom out
l/j	- increase/decrease zoom speed
w/a/s/d - pan
q/e	- increase/decrease pan speed
u	- reset zoom and pan speed
o	- toggle scale modes

current zoom speed: 1
current pan speed: 10
EOF

escape_char=$(printf "\u1b")
zoom_speed=1
pan_speed=10
help_lenght=15
while true; do
	read -rsn1 mode # get 1 character
	if [[ $mode == $escape_char ]]; then
	    read -rsn2 mode # read 2 more chars
	fi
	case $mode in
	    'p') echo Quitting... ; tput sgr0; tput cnorm; tput rmcup || clear; exit 0 ;;
	    #'[A') echo UP ;;
	    #'[B') echo DN ;;
	    '[D') imv-msg "$1" p ;;
	    '[C') imv-msg "$1" n ;;
	    'f') imv-msg "$1" fullscreen ;;
	    'i') imv-msg "$1" zoom "$zoom_speed" ;;
	    'k') imv-msg "$1" zoom "-$zoom_speed" ;;
	    'l') zoom_speed=$((zoom_speed+1)) ; tput sc ; tput cup "$help_lenght" 20 ; echo "$zoom_speed        " ; tput sc ;;
	    'j') zoom_speed=$((zoom_speed-1))  ; if [ "$zoom_speed" -lt 0 ] ; then zoom_speed=0 ; fi ; tput sc ; tput cup "$help_lenght" 20 ; echo "$zoom_speed        " ; tput sc ;;
	    'd') imv-msg "$1" pan "$pan_speed" 0 ;;
	    'a') imv-msg "$1" pan "-$pan_speed" 0 ;;
	    's') imv-msg "$1" pan 0 "$pan_speed" ;;
	    'w') imv-msg "$1" pan 0 "-$pan_speed" ;;
	    'e') pan_speed=$((pan_speed+5)) ; tput sc ; tput cup $(($help_lenght+1)) 19 ; echo "$pan_speed        " ; tput sc ;;
	    'q') pan_speed=$((pan_speed-5)) ; if [ "$pan_speed" -lt 0 ] ; then pan_speed=0 ; fi ; tput sc ; tput cup $(($help_lenght+1)) 19 ; echo "$pan_speed        " ; tput sc ;;
	    'u') zoom_speed=1 ; pan_speed=10 ; tput sc ; tput cup "$help_lenght" 20 ; echo "$zoom_speed        " ; tput sc ;;
	    'o') imv-msg "$1" scaling next ;;


	    *) continue ;;
	esac
done