]> gitweb.factorcode.org Git - factor.git/blob - extra/progress-bars/progress-bars.factor
change ERROR: words from throw-foo back to foo.
[factor.git] / extra / progress-bars / progress-bars.factor
1 ! Copyright (C) 2011 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators.short-circuit kernel math math.order
4 sequences ;
5 IN: progress-bars
6
7 ERROR: invalid-percent x ;
8
9 : check-percent ( x -- x )
10     dup 0 1 between? [ invalid-percent ] unless ;
11
12 ERROR: invalid-length x ;
13
14 : check-length ( x -- x )
15     dup { [ 0 > ] [ integer? ] } 1&& [ invalid-length ] unless ;
16
17 : (make-progress-bar) ( percent len completed-ch pending-ch -- string )
18     [ [ * >integer ] keep over - ] 2dip
19     [ <repetition> ] bi-curry@ bi* "" append-as ;
20
21 : make-progress-bar ( percent length -- string )
22     [ check-percent ] [ check-length ] bi*
23     CHAR: = CHAR: - (make-progress-bar) ;