#!/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