From 9a0a030cc83559084e6e4637fbcaed43face6217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 23 Apr 2019 23:14:35 +0200 Subject: Move some procedures. --- module/output/general.scm | 18 +++++++++++------- module/output/html.scm | 14 +------------- module/output/text.scm | 8 ++++++++ 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))) -- cgit v1.2.3