aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-04-23 23:14:35 +0200
committerHugo Hörnquist <hugo@hornquist.se>2019-04-23 23:14:35 +0200
commit9a0a030cc83559084e6e4637fbcaed43face6217 (patch)
tree095ca54a05a7244002d1fdf9afd4a7afd875065d
parentTerm display now reacts more to terminal size. (diff)
downloadcalp-9a0a030cc83559084e6e4637fbcaed43face6217.tar.gz
calp-9a0a030cc83559084e6e4637fbcaed43face6217.tar.xz
Move some procedures.
-rw-r--r--module/output/general.scm18
-rw-r--r--module/output/html.scm14
-rw-r--r--module/output/text.scm8
3 files changed, 20 insertions, 20 deletions
diff --git a/module/output/general.scm b/module/output/general.scm
index f455f18b..526c449e 100644
--- a/module/output/general.scm
+++ b/module/output/general.scm
@@ -1,10 +1,14 @@
(define-module (output general)
)
-(define-public (trim-to-width str len)
- (let ((trimmed (string-pad-right str len)))
- (if (< (string-length trimmed)
- (string-length str))
- (string-append (string-drop-right trimmed 1)
- "…")
- trimmed)))
+;; Returns a color with good contrast to the given background color.
+(define-public (calculate-fg-color c)
+ (define (str->num c n) (string->number (substring/shared c n (+ n 2)) 16))
+ (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.144 b))
+ #xFF))
+ "#000000" "#e5e8e6")))
diff --git a/module/output/html.scm b/module/output/html.scm
index 3df3c713..812e9d79 100644
--- a/module/output/html.scm
+++ b/module/output/html.scm
@@ -8,6 +8,7 @@
#:use-module (util tree)
#:use-module (srfi srfi-19)
#:use-module (srfi srfi-19 util)
+ #:use-module (output general)
#:use-module (parameters)
#:use-module (config))
@@ -107,7 +108,6 @@
" "
,@(stream->list (stream-map (lambda (e) (vevent->sxml date e)) events))))))
-
(define (time-marker-div)
(map (lambda (time)
`(div (@ (id ,(string-append "clock-" time))
@@ -118,18 +118,6 @@
(define (d str)
(string->date str "~Y-~m-~d"))
-
-(define (calculate-fg-color c)
- (define (str->num c n) (string->number (substring/shared c n (+ n 2)) 16))
- (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.144 b))
- #xFF))
- "black" "#e5e8e6")))
-
(define (include-css path)
`(link (@ (type "text/css")
(rel "stylesheet")
diff --git a/module/output/text.scm b/module/output/text.scm
index e86f4664..cca87678 100644
--- a/module/output/text.scm
+++ b/module/output/text.scm
@@ -51,3 +51,11 @@
(map (lambda (line) (justify-line line #:width width))
(lines str)))
height)))
+
+(define-public (trim-to-width str len)
+ (let ((trimmed (string-pad-right str len)))
+ (if (< (string-length trimmed)
+ (string-length str))
+ (string-append (string-drop-right trimmed 1)
+ "…")
+ trimmed)))