#!/bin/bash

export FRAMEBUFFER=/dev/fb0

IDUMP_OPT="-f"
FILES=($@)
INDEX=0

#echo "file num: ${#FILES[@]}"
if test ${#FILES[@]} -le "0"; then
	exit 0
fi

tput civis

#echo -n "filename:${FILES[$INDEX]} index:$INDEX"
idump "$IDUMP_OPT" "${FILES[$INDEX]}" > /dev/null 2>&1

while :; do
	read -s -n 1 KEY

	#tput cr
	#tput el

	case "$KEY" in
	"w")
		INDEX=`expr $INDEX + 1`;;
	"W")
		INDEX=`expr $INDEX + 10`;;
	"m")
		INDEX=`expr $INDEX - 1`;;
	"M")
		INDEX=`expr $INDEX - 10`;;
	"q")
		tput cnorm
		exit 0;;
	esac

	if test $INDEX -lt "0"; then
		INDEX=`expr ${#FILES[@]} - 1`
	elif test $INDEX -ge "${#FILES[@]}"; then
		INDEX=0
	fi

	#echo -n "filename:${FILES[$INDEX]} index:$INDEX"
	idump "$IDUMP_OPT" "${FILES[$INDEX]}" > /dev/null 2>&1
done
