source: common/progress_bar.sh@ c5ae20a

experimental
Last change on this file since c5ae20a was 9c9775f, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Updated experimental branch to current trunk code.

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[460ea63]1
2# $Id$
3
4set -e
5
[9199a13]6# Be sure that we know the taget name
[460ea63]7[[ -z $1 ]] && exit
[9199a13]8TARGET=$1 # Remember the target build we are looking for
[50fb011]9MAKE_PPID=$2
[460ea63]10
[9199a13]11declare -r CSI=$'\e[' # DEC terminology, Control Sequence Introducer
12declare -r CURSOR_OFF=${CSI}$'?25l'
13declare -r CURSOR_ON=${CSI}$'?25h'
14declare -r ERASE_LINE=${CSI}$'2K'
15declare -r FRAME_OPEN=${CSI}$'2G['
16declare -r FRAME_CLOSE=${CSI}$'63G]'
17declare -r TS_POSITION=${CSI}$'65G'
[ae08ff1]18declare -r LINE_WRAP_OFF=${CSI}$'?7l'
19declare -r LINE_WRAP_ON=${CSI}$'?7h'
[9199a13]20declare -a RESET_LINE=${CURSOR_OFF}${ERASE_LINE}${FRAME_OPEN}${FRAME_CLOSE}
21
22declare -a GRAPHIC_STR="| / - \\ + "
23declare -i SEC=0 # Seconds accumulator
24declare -i PREV_SEC=0
25
[9c9775f]26# Prevent segfault on stripping phases
27if [[ "$BASHBIN" = "/tools/bin/bash" ]] ; then
28 SLEEP=/tools/bin/sleep
29else
30 SLEEP=/bin/sleep
31fi
32
[9199a13]33write_or_exit() {
34 # make has been killed or failed or run to completion, leave
[50fb011]35 [[ ! -e /proc/${MAKE_PPID} ]] && echo -n "${CURSOR_ON}" && exit
[3b63c8c]36
[9199a13]37 # Target build complete, leave.
38 [[ -f ${TARGET} ]] && echo -n "${CURSOR_ON}" && exit
[3b63c8c]39
[9199a13]40 # It is safe to write to the screen
41 echo -n "$1"
42}
43
44 # initialize screen
[ae08ff1]45write_or_exit "${RESET_LINE}${TS_POSITION}0 min. 0 sec"
[9199a13]46
47 # loop forever..
48while true ; do
49
50 # Loop through the animation string
51 for GRAPHIC_CHAR in ${GRAPHIC_STR} ; do
52 write_or_exit "${CSI}$((SEC + 3))G${GRAPHIC_CHAR}"
[9c9775f]53 $SLEEP .12 # This value MUST be less than .2 seconds.
[9199a13]54 done
55
56 # A BASH internal variable, the number of seconds the script
57 # has been running. modulo convert to 0-59
58 SEC=$(($SECONDS % 60))
59
60 # Detect rollover of the seconds.
61 (( PREV_SEC > SEC )) && write_or_exit "${RESET_LINE}"
62 (( PREV_SEC = SEC ))
63
64 # Display the accumulated time. div minutes.. modulo seconds.
[ae08ff1]65 write_or_exit "${TS_POSITION}$(($SECONDS / 60)) min. $SEC sec"
[9199a13]66done
67
68exit
Note: See TracBrowser for help on using the repository browser.