From c3ed0230df578ce934289e3064b987ab86d602f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 29 Mar 2019 15:32:52 +0100 Subject: Add summary-filter to SUMMARY field. --- module/config.scm | 24 +++++++++++++++++++++++- module/main.scm | 5 ++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/module/config.scm b/module/config.scm index 3c6ebbb0..54cda06b 100644 --- a/module/config.scm +++ b/module/config.scm @@ -4,9 +4,31 @@ (use-modules (srfi srfi-26) - (ice-9 ftw)) + (srfi srfi-88) + (ice-9 ftw) + (ice-9 regex) + (ice-9 rdelim)) (define calendar-files (let ((path (string-append (getenv "HOME") "/.calendars/"))) (map (cut string-append path <>) (scandir path (lambda (str) (not (char=? #\. (string-ref str 0)))))))) + +;;; TODO possibly replace with propper lookup +(define my-courses + '((TSEA82 . "Datorteknik") + (TFYA19 . "Kvantdatorer") + (TATA42 . "TvÄvarren") + (TSRT04 . "Matlab") + (TDDC78 . "Paralellprogrammering") + (TDDB68 . "Pintos"))) + +(define* (aref alist key optional: default) + (or (assoc-ref alist key) default key)) + + +(define (summary-filter ev str) + (regexp-substitute/global + #f "T[A-Z]{3}[0-9]{2}" str + 'pre (lambda (m) (aref my-courses (string->symbol (match:substring m)))) + 'post)) diff --git a/module/main.scm b/module/main.scm index 995e55a6..aae640ac 100755 --- a/module/main.scm +++ b/module/main.scm @@ -41,6 +41,8 @@ (define (now) (date->time-utc (current-date))) +(define (summary-filter _ str) str) + (define (main-loop regular-events repeating-events) (define time (now)) (define cur-event 0) @@ -76,7 +78,8 @@ (time->string (attr ev 'DTSTART) "~1 ~3") ; TODO show truncated string (if (= i cur-event) "\x1b[7m" "") (color-escape (attr (parent ev) 'COLOR)) - (trim-to-width (attr ev 'SUMMARY) 30) + ;; Summary filter is a hook for the user + (trim-to-width (summary-filter ev (attr ev 'SUMMARY)) 30) STR-RESET (trim-to-width (or (attr ev 'LOCATION) "\x1b[1;30mINGEN LOKAL") 20) -- cgit v1.2.3