#!/bin/bash
#
# barformat
# This file is part of Raider

ctlc_close_barformat() { # close progress bar after ctrl-c
	"rm" -f $BAR_SEMAF >/dev/null 2>&1	# close progress bar
	>${TRAP_TRIGGERED}
	sleep 1.2	# Wait for all the output 
	echo -e "\nStopped with Ctrl+C break"
	exit 1
}

bar_format() {	# progress bar in partition format
	local barlength=0
	local lengthstr=15
	local delete="$(repeatchar '\b' $lengthstr)$(spaces $lengthstr)$(repeatchar '\b' $lengthstr)"
	while true
	do
		if [ $barlength -ge $lengthstr ]; then
			barlength=0
			echo -ne "$delete"
		fi
		if ! [ -f $BAR_SEMAF ];then
			if ! [ -f $TRAP_TRIGGERED ]; then
				echo "> Done."
			else
				"rm" -f $TRAP_TRIGGERED >/dev/null 2>&1
			fi
			exit
		else
			for i in "|" "\b/" "\b-" "\b\\" "\b|" "\b>"
			do
				echo -ne $i
				sleep .1
			done
			sleep .5
			echo -ne "\b="
			sleep .1
			barlength=$((barlength+1))
		fi
	done
	exit 
}





