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 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'module/output/general.scm') 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"))) -- cgit v1.2.3