Document the progress module.
This commit is contained in:
parent
019136319f
commit
f870430cf1
2 changed files with 41 additions and 3 deletions
35
README.md
35
README.md
|
@ -90,6 +90,41 @@ Support Modules
|
||||||
|
|
||||||
### Progress
|
### Progress
|
||||||
|
|
||||||
|
Provides syntax forms and procedures for showing progress of a
|
||||||
|
process.
|
||||||
|
|
||||||
|
(with-progress echo? pre post body ...)
|
||||||
|
|
||||||
|
* ```echo?``` - flag enabling progress output
|
||||||
|
* ```pre``` - string to be printed at start
|
||||||
|
* ```post``` - string to be printed after finish
|
||||||
|
* ```body ...``` - expressions of the process tracked
|
||||||
|
|
||||||
|
Displays process progress starting with the ```pre``` string, adding
|
||||||
|
arbitrary string to the output using the ```progress-advance``` during
|
||||||
|
each and every step. If the process reaches its finish, the output
|
||||||
|
line is finished with the ```post``` string and cursor is moved to new
|
||||||
|
line.
|
||||||
|
|
||||||
|
During the steps, the whole line is always refreshed when the progress
|
||||||
|
gets updated.
|
||||||
|
|
||||||
|
If ```echo?``` is ```#f``` (false), nothing is output.
|
||||||
|
|
||||||
|
(progress-advance [str])
|
||||||
|
|
||||||
|
* ```str``` - string to add to progress, defaults to "."
|
||||||
|
|
||||||
|
Adds given string to current progress and refreshes the progress
|
||||||
|
line. Must be evaluated within ```with-progress``` expression.
|
||||||
|
|
||||||
|
(progress-break body ...)
|
||||||
|
|
||||||
|
* ```body ...``` - arbitrary expressions to be evaluated
|
||||||
|
|
||||||
|
Evaluates the ```body ...``` expressions. Hides current progress line
|
||||||
|
before the evaluation and redisplays it when finished.
|
||||||
|
|
||||||
### Testing
|
### Testing
|
||||||
|
|
||||||
This module provides simple syntax forms for (unit) testing of other
|
This module provides simple syntax forms for (unit) testing of other
|
||||||
|
|
|
@ -50,10 +50,13 @@
|
||||||
(display (sprintf "\r\x1b[K~A" cp)))))
|
(display (sprintf "\r\x1b[K~A" cp)))))
|
||||||
|
|
||||||
;; Adds something to current progress and refreshes the display.
|
;; Adds something to current progress and refreshes the display.
|
||||||
(define (progress-advance str)
|
(define (progress-advance . args)
|
||||||
(when (*current-progress*)
|
(when (*current-progress*)
|
||||||
(*current-progress* (string-append (*current-progress*) (sprintf "~A" str)))
|
(let ((str (if (null? args)
|
||||||
(print-current-progress)))
|
"."
|
||||||
|
(car args))))
|
||||||
|
(*current-progress* (string-append (*current-progress*) (sprintf "~A" str)))
|
||||||
|
(print-current-progress))))
|
||||||
|
|
||||||
;; Runs given procedure within progress environment
|
;; Runs given procedure within progress environment
|
||||||
(define (run-with-progress echo? pre-msg post-msg thunk)
|
(define (run-with-progress echo? pre-msg post-msg thunk)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue