progress_bar.. improving the accuracy

George Boudreau georgeb at linuxfromscratch.org
Fri Jun 9 20:34:29 PDT 2006


Manuel,

   I see you are trying to fine tune the delay variable, compensate for 
bash overhead. I did not know you wanted a precise time display so I 
never validated the timestamp.. it looked close enough for government 
work :-) However it lost time even on my machine.

   I have included a different concept for the progress bar. Instead of 
counting seconds via timed loop just use the bash internal variable 
$SECONDS.

   notes::
   Occasionally you will see an empty space in the progress bar and that 
is due to the priority assigned to unpacking a large package. Since we 
are using actual seconds and not counts the space will be 'missed' 
seconds.  The graphic chars are written to a cursor location set by the 
'second' and not an incremented counter. Also, if we miss the the magic 
60th second we will catch the rollover and reset the line later.

   Does this method have holes.. possibly, I thought the previous 
version was usable (and I was wrong)


   # initialize screen
write_or_exit "${RESET_LINE}${TS_POSITION}0 min. 0 sec. "
while true ; do  # loop forever..

       # Loop through the animation string
     for GRAPHIC_CHAR in ${GRAPHIC_STR} ; do
       write_or_exit "${CSI}$((SEC + 3))G${GRAPHIC_CHAR}"
       sleep .14  # This value MUST be less than .2 seconds.
     done

       # A BASH internal variable, the number of seconds the script
       # has been running. modulo convert to 0-59
     SEC=$(($SECONDS % 60))

       # Detect rollover of the seconds..
     (( PREV_SEC > SEC )) && write_or_exit "${RESET_LINE}"
     (( PREV_SEC = SEC ))

       # Display the accumulated time. div minutes.. modulo seconds.
     write_or_exit "${TS_POSITION}$(($SECONDS / 60)) min. $SEC sec. "
done
-------------- next part --------------
A non-text attachment was scrubbed...
Name: progress_bar.sh
Type: application/x-sh
Size: 1983 bytes
Desc: not available
URL: <http://lists.linuxfromscratch.org/pipermail/alfs-discuss/attachments/20060609/f8e6000a/attachment.sh>


More information about the alfs-discuss mailing list