Duck util-stdout.
This commit is contained in:
parent
323293be0e
commit
b027d19f49
5 changed files with 57 additions and 33 deletions
|
@ -25,8 +25,11 @@
|
|||
|
||||
(declare (unit util-stdout))
|
||||
|
||||
(module
|
||||
(import duck)
|
||||
|
||||
(module*
|
||||
util-stdout
|
||||
#:doc ("Very simple module wrapping standard output.")
|
||||
(
|
||||
*stdout-quiet*
|
||||
stdout-print
|
||||
|
@ -39,20 +42,28 @@
|
|||
(chicken format))
|
||||
|
||||
;; If true, all stdout output is suppresed
|
||||
(define *stdout-quiet* (make-parameter #f))
|
||||
(define/doc *stdout-quiet*
|
||||
("A boolean parameter which disables all output from procedures in this
|
||||
module if its value is ```#t```.")
|
||||
quiet
|
||||
(make-parameter #f))
|
||||
|
||||
;; Prints to stdout if not quiet
|
||||
(define (stdout-print . args)
|
||||
(define/doc (stdout-print . args)
|
||||
("If not quiet, passes ```args``` to ```print```.")
|
||||
(when (not (*stdout-quiet*))
|
||||
(apply print args)))
|
||||
|
||||
;; Prints formatted string to stdout if not quiet
|
||||
(define (stdout-printf fmt . args)
|
||||
(define/doc (stdout-printf fmt . args)
|
||||
("If not quiet, prints formatted string ```fmt``` by applying ```args```
|
||||
to ```format``` procedure.")
|
||||
(when (not (*stdout-quiet*))
|
||||
(print (apply format fmt args))))
|
||||
|
||||
;; Prints newline if not quiet
|
||||
(define (stdout-newline)
|
||||
(define/doc (stdout-newline)
|
||||
("If not quiet, calls ```(newline)```.")
|
||||
(when (not (*stdout-quiet*))
|
||||
(newline)))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue