aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-05-08 22:01:27 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2019-05-08 22:01:27 +0200
commitcef9ad394f015fadfdf620507cf466b5158f63ac (patch)
treea2d0278db5e23401530c63338468a2ed3e391cb0
parentAdd glob routine. (diff)
downloadcalp-cef9ad394f015fadfdf620507cf466b5158f63ac.tar.gz
calp-cef9ad394f015fadfdf620507cf466b5158f63ac.tar.xz
Add flags for just running the text flower.
It's twisted if one program should do many things, or just a single thing. If we assume that this program does two things: reading calendar files, and writing output, then it should be ok to allow any of those parts to run independentally of the other. Making it ok to just run the text flower.
-rwxr-xr-xmodule/main.scm39
-rw-r--r--module/output/text.scm10
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)))