Skip to content

Commit

Permalink
disable echoing of keystroke during animations
Browse files Browse the repository at this point in the history
  • Loading branch information
phyver committed Jun 7, 2021
1 parent 2d89cdb commit 5af0ce9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
8 changes: 5 additions & 3 deletions bin/progress_bar
Expand Up @@ -181,9 +181,10 @@ init_data() {

animation() {
# Hide cursor.
tput civis 2> /dev/null
tput civis 2>/dev/null
stty -echo 2>/dev/null
# the additional \b\b\b \b\b\b is used to erase the possible ^C
trap 'tput cnorm 2> /dev/null;printf "\b\b\b \b\b\b$POST";exit 1' INT TERM QUIT HUP
trap 'tput cnorm 2>/dev/null; stty echo 2>/dev/null; printf "\b\b\b \b\b\b$POST";exit 1' INT TERM QUIT HUP

# Print initial message.
printf "$MSG"
Expand Down Expand Up @@ -236,7 +237,8 @@ EOS
then
animation
printf "$POST"
tput cnorm 2> /dev/null
tput cnorm 2>/dev/null
stty echo 2>/dev/null
fi
}

Expand Down
2 changes: 1 addition & 1 deletion bin/progress_bar.sh
Expand Up @@ -38,6 +38,6 @@ else
rm -f "$stderr_log"
unset stderr_log design
wait $_PID
unset $_PID
unset _PID
set -m
fi
24 changes: 16 additions & 8 deletions start.sh
Expand Up @@ -135,36 +135,38 @@ _confirm_passport() {
}

progress() {
# hide cursor
tput civis 2> /dev/null
trap "tput cnorm 2> /dev/null;echo;exit 1" INT TERM QUIT
if [ -z "$progress_I" ]
then
progress_filename=$GSH_ROOT/lib/ascii-art/titlescreen
local N=$(wc -l "$GSH_CONFIG/index.txt" | awk '{print $1}')
local size=$(wc -c "$progress_filename" | awk '{print $1}')
progress_delta=$((size/N + 1))
# head -c$((progress_delta - 1)) $progress_filename => not POSIX compliant
dd if="$progress_filename" bs="$progress_delta" count=1 2> /dev/null
dd if="$progress_filename" bs="$progress_delta" count=1 2>/dev/null
progress_I=1
else
# tail -c+$((progress_I * progress_delta)) $progress_filename | head -c$progress_delta => not POSIX compliant
dd if="$progress_filename" bs="$progress_delta" skip="$progress_I" count=1 2> /dev/null
dd if="$progress_filename" bs="$progress_delta" skip="$progress_I" count=1 2>/dev/null
progress_I=$((progress_I+1))
fi
}

progress_finish() {
# tail -c+$((progress_I*progress_delta)) $progress_filename => not POSIX compliant
dd if="$progress_filename" bs="$progress_delta" skip="$progress_I" 2> /dev/null
dd if="$progress_filename" bs="$progress_delta" skip="$progress_I" 2>/dev/null
unset progress_filename progress_delta progress_I
# show cursor
tput cnorm 2> /dev/null
# show cursor and enable echo of keystrokes
}


init_gsh() {

# hide cursor and disable echoing of keystrokes
tput civis 2>/dev/null
trap "tput cnorm 2>/dev/null; stty echo 2>/dev/null; echo; exit 1" INT TERM QUIT

stty -echo

ADMIN_HASH='b88968dc60b003b9c188cc503a457101b4087109' # default for 'gsh'

# message when data from a previous play is found. We can either
Expand Down Expand Up @@ -385,6 +387,8 @@ Aborting.")"
[ "$GSH_VERBOSE_DEBUG" != true ] && echo "[DONE]" >&2
else
progress_finish
# show cursor back
tput cnorm 2>/dev/null
echo
printf "$(gettext "Press Enter to continue.")"
stty -echo 2>/dev/null # ignore errors, in case input comes from a redirection
Expand All @@ -393,6 +397,10 @@ Aborting.")"
clear
fi
unset MISSION_DIR MISSION_NB

# show cursor and re-enable echoing of keystrokes
tput cnorm 2>/dev/null
stty echo 2>/dev/null
}

#######################################################################
Expand Down

0 comments on commit 5af0ce9

Please sign in to comment.