Changeset ddf5f77


Ignore:
Timestamp:
06/10/2006 03:41:52 PM (18 years ago)
Author:
Manuel Canales Esparcia <manuel@…>
Branches:
1.0, 2.3, 2.3.x, 2.4, ablfs, ablfs-more, legacy, new_features, trunk
Children:
93f38e7
Parents:
4a444f1
Message:

Using Bash internal $SECONDS to meassure the time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/progress_bar.sh

    r4a444f1 rddf5f77  
    1919
    2020declare -a  GRAPHIC_STR="| / - \\ + "
    21 declare -i  MIN=0  # Start value for minutes
    2221declare -i  SEC=0  # Seconds accumulator
    23 declare -i  POS=0  # Start value for seconds/cursor position
     22declare -i  PREV_SEC=0
     23
    2424
    2525write_or_exit() {
     
    3434}
    3535
    36   # This will loop forever.. or overflow, which ever comes first :)
    37 for ((MIN=0; MIN >= 0; MIN++)); do
    38   write_or_exit "${RESET_LINE}${TS_POSITION}${MIN} min. 0 sec. "
    39   # Count the seconds
    40   for ((SEC=1, POS=3; SEC <= 60; SEC++, POS++)); do
     36  # initialize screen
     37write_or_exit "${RESET_LINE}${TS_POSITION}0 min. 0 sec. "
     38
     39  # loop forever..
     40while true ; do
     41
     42      # Loop through the animation string
    4143    for GRAPHIC_CHAR in ${GRAPHIC_STR} ; do
    42       write_or_exit "${CSI}${POS}G${GRAPHIC_CHAR}"
    43       # Compensate code execution time (need verification on other machines)
    44       sleep .137
     44      write_or_exit "${CSI}$((SEC + 3))G${GRAPHIC_CHAR}"
     45      sleep .12 # This value MUST be less than .2 seconds.
    4546    done
    46       # Display the accumulated time.
    47     write_or_exit "${TS_POSITION}${MIN} min. ${SEC} sec. "
    48   done
     47
     48      # A BASH internal variable, the number of seconds the script
     49      # has been running. modulo convert to 0-59
     50    SEC=$(($SECONDS % 60))
     51
     52      # Detect rollover of the seconds.
     53    (( PREV_SEC > SEC )) && write_or_exit "${RESET_LINE}"
     54    (( PREV_SEC = SEC ))
     55
     56      # Display the accumulated time. div minutes.. modulo seconds.
     57    write_or_exit "${TS_POSITION}$(($SECONDS / 60)) min. $SEC sec. "
    4958done
     59
    5060exit
    51 
Note: See TracChangeset for help on using the changeset viewer.