aboutsummaryrefslogtreecommitdiff
path: root/module/output
diff options
context:
space:
mode:
Diffstat (limited to 'module/output')
-rw-r--r--module/output/color.scm22
-rw-r--r--module/output/vdir.scm55
2 files changed, 22 insertions, 55 deletions
diff --git a/module/output/color.scm b/module/output/color.scm
new file mode 100644
index 00000000..123d0ba2
--- /dev/null
+++ b/module/output/color.scm
@@ -0,0 +1,22 @@
+(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/output/vdir.scm b/module/output/vdir.scm
deleted file mode 100644
index 2541f0f9..00000000
--- a/module/output/vdir.scm
+++ /dev/null
@@ -1,55 +0,0 @@
-;;; Commentary:
-;;; Module for writing components to the vdir storage format.
-;;; Currently also has some cases for "big" icalendar files,
-;;; but those are currently unsupported.
-
-;;; TODO generalize save-event and remove-event into a general interface,
-;;; which different database backends can implement. Actually, do that for all
-;;; loading and writing.
-
-;;; Code:
-
-(define-module (output vdir)
- :use-module (util)
- :use-module (vcomponent ical output)
- :use-module (vcomponent)
- :use-module ((util io) :select (with-atomic-output-to-file))
- )
-
-
-(define / file-name-separator-string)
-
-(define-public (save-event event)
- (define calendar (parent event))
- (case (prop calendar '-X-HNH-SOURCETYPE)
- [(file)
- (error "Importing into direct calendar files not supported")]
-
- [(vdir)
- (let* ((uid (or (prop event 'UID) (uuidgen))))
- (set! (prop event 'UID) uid
- ;; TODO use existing filename if present?
- (prop event '-X-HNH-FILENAME) (string-append
- (prop calendar '-X-HNH-DIRECTORY)
- / uid ".ics"))
- (with-atomic-output-to-file (prop event '-X-HNH-FILENAME)
- (lambda () (print-components-with-fake-parent (list event))))
- uid)]
-
- [else
- (error "Source of calendar unknown, aborting.")
- ]))
-
-
-(define-public (remove-event event)
- (define calendar (parent event))
- (case (prop calendar '-X-HNH-SOURCETYPE)
- [(file)
- (error "Removing events from large files unsupported")]
-
- [(vdir)
- (delete-file (prop event '-X-HNH-FILENAME))]
-
- [else
- (error "Source of calendar unknown, aborting.")
- ]))