From f12fca91b185cbf83fbe173fadf6a46f6c3c0c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 17 Aug 2020 18:39:53 +0200 Subject: Fixes. --- module/calp/entry-points/import.scm | 4 +++- module/html/vcomponent.scm | 2 +- module/output/color.scm | 22 ---------------------- module/util.scm | 12 +++++++----- module/util/color.scm | 22 ++++++++++++++++++++++ module/vcomponent/ical/output.scm | 1 - module/vcomponent/vdir/parse.scm | 4 ++-- module/vcomponent/vdir/save-delete.scm | 5 +++-- module/vcomponent/xcal/output.scm | 1 - module/vcomponent/xcal/types.scm | 1 - tests/xcal.scm | 2 +- 11 files changed, 39 insertions(+), 37 deletions(-) delete mode 100644 module/output/color.scm create mode 100644 module/util/color.scm diff --git a/module/calp/entry-points/import.scm b/module/calp/entry-points/import.scm index b13832cc..e8c46ea8 100644 --- a/module/calp/entry-points/import.scm +++ b/module/calp/entry-points/import.scm @@ -5,7 +5,9 @@ :use-module (ice-9 getopt-long) :use-module (ice-9 rdelim) :use-module (srfi srfi-1) - :use-module (output vdir) + ;; TODO FIX + ;; :use-module (output vdir) + :use-module ((vcomponent vdir save-delete) :select (save-event)) :use-module (vcomponent) :autoload (vcomponent instance) (global-event-object) ) diff --git a/module/html/vcomponent.scm b/module/html/vcomponent.scm index 5743ff42..fc70be1b 100644 --- a/module/html/vcomponent.scm +++ b/module/html/vcomponent.scm @@ -7,7 +7,7 @@ :use-module (html util) :use-module ((html config) :select (edit-mode)) :use-module ((html components) :select (btn tabset)) - :use-module ((output color) :select (calculate-fg-color)) + :use-module ((util color) :select (calculate-fg-color)) :use-module ((vcomponent datetime output) :select (fmt-time-span format-description diff --git a/module/output/color.scm b/module/output/color.scm deleted file mode 100644 index 123d0ba2..00000000 --- a/module/output/color.scm +++ /dev/null @@ -1,22 +0,0 @@ -(define-module (output color) - ) - -;; Returns a color with good contrast to the given background color. -;; https://stackoverflow.com/questions/1855884/determine-font-color-based-on-background-color/1855903#1855903 -(define-public (calculate-fg-color c) - (catch #t - (lambda () - (define (str->num c n) (string->number (substring/shared c n (+ n 2)) 16)) - ;; (format (current-error-port) "COLOR = ~s~%" c) - (let ((r (str->num c 1)) - (g (str->num c 3)) - (b (str->num c 5))) - (if (< 1/2 (/ (+ (* 0.299 r) - (* 0.587 g) - (* 0.114 b)) - #xFF)) - "#000000" "#FFFFFF"))) - (lambda args - (format (current-error-port) "Error calculating foreground color?~%~s~%" args) - "#FF0000" - ))) diff --git a/module/util.scm b/module/util.scm index e2acd551..28864896 100644 --- a/module/util.scm +++ b/module/util.scm @@ -309,11 +309,6 @@ (define-public (as-symb s) (if (string? s) (string->symbol s) s)) -(define-public (downcase-symbol symb) - (-> symb - symbol->string - string-downcase - string->symbol)) (define-public (enumerate lst) @@ -505,6 +500,13 @@ (and=>> (and=> value proc) rest ...)])) +(define-public (downcase-symbol symb) + (-> symb + symbol->string + string-downcase + string->symbol)) + + ;; @example ;; (group (iota 10) 2) ;; ⇒ ((0 1) (2 3) (4 5) (6 7) (8 9)) diff --git a/module/util/color.scm b/module/util/color.scm new file mode 100644 index 00000000..7b6dacec --- /dev/null +++ b/module/util/color.scm @@ -0,0 +1,22 @@ +(define-module (util color) + ) + +;; Returns a color with good contrast to the given background color. +;; https://stackoverflow.com/questions/1855884/determine-font-color-based-on-background-color/1855903#1855903 +(define-public (calculate-fg-color c) + (catch #t + (lambda () + (define (str->num c n) (string->number (substring/shared c n (+ n 2)) 16)) + ;; (format (current-error-port) "COLOR = ~s~%" c) + (let ((r (str->num c 1)) + (g (str->num c 3)) + (b (str->num c 5))) + (if (< 1/2 (/ (+ (* 0.299 r) + (* 0.587 g) + (* 0.114 b)) + #xFF)) + "#000000" "#FFFFFF"))) + (lambda args + (format (current-error-port) "Error calculating foreground color?~%~s~%" args) + "#FF0000" + ))) diff --git a/module/vcomponent/ical/output.scm b/module/vcomponent/ical/output.scm index ff5465c6..ec2458ba 100644 --- a/module/vcomponent/ical/output.scm +++ b/module/vcomponent/ical/output.scm @@ -14,7 +14,6 @@ :use-module (vcomponent recurrence) :use-module (vcomponent geo) :use-module (vcomponent ical types) - :use-module (output common) :autoload (vcomponent instance) (global-event-object) :use-module ((datetime instance) :select (zoneinfo)) ) diff --git a/module/vcomponent/vdir/parse.scm b/module/vcomponent/vdir/parse.scm index ae4ea692..c4b1b694 100644 --- a/module/vcomponent/vdir/parse.scm +++ b/module/vcomponent/vdir/parse.scm @@ -4,7 +4,7 @@ ;; (vcomponent parse ical) handles reading data from icalendar files. ;;; Code: -(define-module (vcomponent parse) +(define-module (vcomponent vdir parse) :use-module (srfi srfi-1) :use-module ((ice-9 hash-table) :select (alist->hash-table)) @@ -24,7 +24,7 @@ ;; All VTIMEZONE's seem to be in "local" time in relation to ;; themselves. Therefore, a simple comparison should work, ;; and then the TZOFFSETTO properties can be subtd. -(define (parse-vdir path) +(define-public (parse-vdir path) (let ((/ (lambda args (string-join args file-name-separator-string 'infix)))) (let ((color (catch 'system-error diff --git a/module/vcomponent/vdir/save-delete.scm b/module/vcomponent/vdir/save-delete.scm index 0bc9cb4a..2cbe96bf 100644 --- a/module/vcomponent/vdir/save-delete.scm +++ b/module/vcomponent/vdir/save-delete.scm @@ -11,6 +11,7 @@ (define-module (vcomponent vdir save-delete) :use-module (util) + :use-module ((util exceptions) :select (assert)) :use-module (vcomponent ical output) :use-module (vcomponent) :use-module ((util io) :select (with-atomic-output-to-file)) @@ -20,7 +21,7 @@ (define-public (save-event event) (define calendar (parent event)) - (assert 'vdir (prop calendar '-X-HNH-SOURCETYPE)) + (assert (eq? 'vdir (prop calendar '-X-HNH-SOURCETYPE))) (let* ((uid (or (prop event 'UID) (uuidgen)))) (set! (prop event 'UID) uid @@ -35,5 +36,5 @@ (define-public (remove-event event) (define calendar (parent event)) - (assert 'vdir (prop calendar '-X-HNH-SOURCETYPE)) + (assert (eq? 'vdir (prop calendar '-X-HNH-SOURCETYPE))) (delete-file (prop event '-X-HNH-FILENAME))) diff --git a/module/vcomponent/xcal/output.scm b/module/vcomponent/xcal/output.scm index 4aa68b00..ec162ec0 100644 --- a/module/vcomponent/xcal/output.scm +++ b/module/vcomponent/xcal/output.scm @@ -5,7 +5,6 @@ :use-module (vcomponent geo) :use-module (vcomponent xcal types) :use-module (ice-9 match) - :use-module (output common) :use-module (datetime) :use-module (srfi srfi-1) ) diff --git a/module/vcomponent/xcal/types.scm b/module/vcomponent/xcal/types.scm index e56ace55..30916a35 100644 --- a/module/vcomponent/xcal/types.scm +++ b/module/vcomponent/xcal/types.scm @@ -2,7 +2,6 @@ :use-module (util) :use-module (vcomponent ical types) :use-module (datetime) - :use-module (output common) ) (define (write-boolean _ v) diff --git a/tests/xcal.scm b/tests/xcal.scm index 33699016..0d4985df 100644 --- a/tests/xcal.scm +++ b/tests/xcal.scm @@ -1,6 +1,6 @@ (((vcomponent xcal parse) sxcal->vcomponent) + ((vcomponent xcal output) vcomponent->sxcal) ((vcomponent ical parse) parse-calendar) - ((output xcal) vcomponent->sxcal) ((util) ->) ((vcomponent base) parameters prop* children) -- cgit v1.2.3