diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2019-12-23 23:40:14 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@hornquist.se> | 2019-12-24 00:02:02 +0100 |
commit | 92b2f429a06ed9b052baff5e27f012397b338f6a (patch) | |
tree | 0ca9c2d8d1d72f5c898ee8384c2ef5459c1ef112 /module/entry-points | |
parent | Move open-{input,output}-port to (util io). (diff) | |
download | calp-92b2f429a06ed9b052baff5e27f012397b338f6a.tar.gz calp-92b2f429a06ed9b052baff5e27f012397b338f6a.tar.xz |
Rework program initialization.
Old init setup had the fancy idea to parse all files before anything
could be done with them. This however led to problems when a part of the
program which didn't care for the calendar files (such as text
formatting).
It also made testing performance almost impossible since to much code
was run before I had a chance to init statprof.
Diffstat (limited to '')
-rw-r--r-- | module/entry-points/html.scm | 35 | ||||
-rw-r--r-- | module/entry-points/ical.scm | 30 | ||||
-rw-r--r-- | module/entry-points/import.scm (renamed from module/output/import.scm) | 10 | ||||
-rw-r--r-- | module/entry-points/info.scm (renamed from module/output/info.scm) | 8 | ||||
-rw-r--r-- | module/entry-points/server.scm (renamed from module/server.scm) | 3 | ||||
-rw-r--r-- | module/entry-points/terminal.scm | 29 | ||||
-rw-r--r-- | module/entry-points/text.scm | 19 |
7 files changed, 129 insertions, 5 deletions
diff --git a/module/entry-points/html.scm b/module/entry-points/html.scm new file mode 100644 index 00000000..699eebdb --- /dev/null +++ b/module/entry-points/html.scm @@ -0,0 +1,35 @@ +(define-module (entry-points html) + :export (main) + :use-module (output html) + :use-module (util) + :use-module (vcomponent) + :use-module (srfi srfi-19) + :use-module (srfi srfi-19 util) + :use-module (ice-9 getopt-long) + + :use-module (parameters) + ;; :use-module (config) + ) + + +(define opt-spec + '((from (value #t) (single-char #\F)) + (to (value #t) (single-char #\T)) + (file (value #t) (single-char #\f)) + (chunked))) + +(define (main args) + (define opts (getopt-long args opt-spec)) + (define start (cond [(option-ref opts 'from #f) => parse-freeform-date] + [else (start-of-month (current-date))])) + (define end (cond [(option-ref opts 'to #f) => parse-freeform-date] + [else (normalize-date* (set (date-month start) = (+ 1)))])) + + (define-values (calendars events) + (load-calendars + calendar-files: (cond [(option-ref opts 'file #f) => list] + [else (calendar-files)]) )) + + (if (option-ref opts 'chunked #f) + (html-chunked-main calendars events start) + (html-generate calendars events start end))) diff --git a/module/entry-points/ical.scm b/module/entry-points/ical.scm new file mode 100644 index 00000000..99253160 --- /dev/null +++ b/module/entry-points/ical.scm @@ -0,0 +1,30 @@ +(define-module (entry-points ical) + :export (main) + :use-module (util) + :use-module (output ical) + :use-module ((vcomponent) :select (load-calendars)) + :use-module ((parameters) :select (calendar-files)) + :use-module (ice-9 getopt-long) + :use-module (srfi srfi-19) + :use-module (srfi srfi-19 util) + ) + +(define opt-spec + '((from (value #t) (single-char #\F)) + (to (value #t) (single-char #\T)))) + +(define (main args) + (define opts (getopt-long args opt-spec)) + + (define start (cond [(option-ref opts 'from #f) => parse-freeform-date] + [else (start-of-month (current-date))])) + (define end (cond [(option-ref opts 'to #f) => parse-freeform-date] + [else (normalize-date* (set (date-month start) = (+ 1)))])) + + (define-values (calendars events) + (load-calendars + calendar-files: (cond [(option-ref opts 'file #f) => list] + [else (calendar-files)]) )) + + (ical-main calendars events start end) + ) diff --git a/module/output/import.scm b/module/entry-points/import.scm index 47f4fd47..5558433b 100644 --- a/module/output/import.scm +++ b/module/entry-points/import.scm @@ -1,5 +1,8 @@ -(define-module (output import) - :use-module (util)) +(define-module (entry-points import) + :export (main) + :use-module (util) + :use-module (ice-9 getopt-long) + ) (define options '((calendar (value #t) (single-char #\c)) @@ -29,3 +32,6 @@ ) + +(define (main . _) + 'noop) diff --git a/module/output/info.scm b/module/entry-points/info.scm index eba0979c..7bc898b2 100644 --- a/module/output/info.scm +++ b/module/entry-points/info.scm @@ -1,4 +1,5 @@ -(define-module (output info) +(define-module (entry-points info) + :export (main) :use-module (util)) (use-modules (ice-9 getopt-long) @@ -7,7 +8,10 @@ (vulgar color) (srfi srfi-1)) -(define-public (info-main calendars events args) +(define (main args) + (define-values (calendars events) + (load-calendars)) + (format #t "~%Found ~a calendars, named:~%~{ - [~4@a] ~a~a\x1b[m~%~}~%" (length calendars) (concatenate diff --git a/module/server.scm b/module/entry-points/server.scm index af87a638..4215ab9a 100644 --- a/module/server.scm +++ b/module/entry-points/server.scm @@ -1,4 +1,5 @@ -(define-module (server) +(define-module (entry-points server) + :export (main) :use-module (util)) (use-modules* (web (server request response uri)) diff --git a/module/entry-points/terminal.scm b/module/entry-points/terminal.scm new file mode 100644 index 00000000..45f9b8eb --- /dev/null +++ b/module/entry-points/terminal.scm @@ -0,0 +1,29 @@ +(define-module (entry-points terminal) + :export (main) + :use-module (output terminal) + :use-module (vcomponent) + :use-module (ice-9 getopt-long) + :use-module (srfi srfi-19) + :use-module (srfi srfi-19 util) + :use-module (parameters) + :use-module (vulgar) + ) + +(define options + '((date (value #t) (single-char #\d)) + (file (value #t) (single-char #\f)))) + +(define (main args) + (define opts (getopt-long args options)) + (define-values (calendars events) + (load-calendars + calendar-files: (cond [(option-ref opts 'file #f) => list] + [else (calendar-files)]) )) + + (let ((time (date->time-utc + (drop-time (or (and=> (option-ref opts 'date #f) parse-freeform-date) + (current-date)))))) + ;; (format (current-error-port) "len(events) = ~a~%" (stream-length events)) + (with-vulgar + (lambda () (main-loop time events)))) +) diff --git a/module/entry-points/text.scm b/module/entry-points/text.scm new file mode 100644 index 00000000..a537b6ac --- /dev/null +++ b/module/entry-points/text.scm @@ -0,0 +1,19 @@ +(define-module (entry-points text) + :export (main) + :use-module (output text) + :use-module (ice-9 getopt-long) + :use-module (util io) + ) + + +(define options + '((width (value #t) (single-char #\w)) + (file (value #t) (single-char #\f)) + )) + +(define (main opts) + (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)) + #:width (or (string->number (option-ref opts 'width "")) 70)))) |