diff options
Diffstat (limited to '')
-rwxr-xr-x | module/main.scm | 39 | ||||
-rw-r--r-- | module/output/text.scm | 10 |
2 files changed, 35 insertions, 14 deletions
diff --git a/module/main.scm b/module/main.scm index 24fdf193..a174a21a 100755 --- a/module/main.scm +++ b/module/main.scm @@ -17,6 +17,7 @@ (output html) (output terminal) (output none) + (output text) (ice-9 getopt-long) @@ -46,7 +47,9 @@ (define options '((mode (value #t) (single-char #\m)) - (files (value #t) (single-char #\f)) + (file (value #t) (single-char #\f)) + (output (value #t) (single-char #\o)) + (format (value #f)) (statprof (value optional)))) (define (ornull a b) @@ -65,16 +68,24 @@ (thunk)))) (lambda () - (init - (lambda (c e) - (let ((ropt (ornull (option-ref opts '() '()) - '("term")))) - ((case (string->symbol (car ropt)) - ((none) none-main) - ((html) html-main) - ((term) terminal-main)) - c e ropt))) - #:calendar-files (or (and=> (option-ref opts 'files #f) - list) - (calendar-files))))) - (newline))) + (with-output-to-port (open-output-port (option-ref opts 'output "-")) + (lambda () + (if (option-ref opts 'format #f) + (for-each (lambda (l) (display l) (newline)) + (flow-text + (with-input-from-port (open-input-port (option-ref opts 'file "-")) + (@ (ice-9 rdelim) read-string)))) + + (init + (lambda (c e) + (let ((ropt (ornull (option-ref opts '() '()) + '("term")))) + ((case (string->symbol (car ropt)) + ((none) none-main) + ((html) html-main) + ((term) terminal-main)) + c e ropt))) + #:calendar-files (or (and=> (option-ref opts 'file #f) + list) + (calendar-files)))) + (newline))))))) diff --git a/module/output/text.scm b/module/output/text.scm index 3b83e115..6e67c7b4 100644 --- a/module/output/text.scm +++ b/module/output/text.scm @@ -59,3 +59,13 @@ (string-append (string-drop-right trimmed 1) "…") trimmed))) + +(define-public (open-input-port str) + (if (string=? "-" str) + (current-input-port) + (open-input-file str))) + +(define-public (open-output-port str) + (if (string=? "-" str) + (current-output-port) + (open-output-file str))) |