Progress

#  Created By    : Dr. Detlef Groth, MPIMG Berlin
#  Last Modified : <050221.1233>
#
#  Description   : snittype for a console progressbar, 
#                  required to get feedback during parsing of gigabytes 
#                  of biological data
#

 
package require snit 0.93

snit::type Progress {
    # options
    option -size ""
    option -file ""
    # variables
    variable state 0
    # typevariables
    constructor {args} {
        $self configurelist $args
        if {[file exists $options(-file)]} {
            set options(-size) [file size $options(-file)]
        }
             
    }   
    # public methods (are lowercase)
    method progress {pos} {
        if {[expr $state + 4] < [expr 1.0 * $pos / $options(-size) * 100]} {
            if {[expr $state % 20] == 0 && $state > 0} {
                puts -nonewline stderr " $state " ;
            } else {
                puts -nonewline stderr "#" 
            }
            incr state 4 
        }
       
    }
    # private methods (are uppercase)
}

# test
proc test {} {
  set p [Progress %AUTO% -size 100]
  for {set i 0} {$i < 100} { incr i} {
    $p progress $i
    update
    after 200
  }
}
# test -> ##### 20 #### 40 #### 60 #### 80 ###

See also text mode (terminal) progress bar / progressbar


See also Snit