From 38077f7748d0c06b6eac5bbb95e38dc521269292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 12 Mar 2019 19:07:10 +0100 Subject: Add interactive terminal UI. --- main.scm | 74 +++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 19 deletions(-) (limited to 'main.scm') diff --git a/main.scm b/main.scm index 7a33b06f..5bf8b6d2 100755 --- a/main.scm +++ b/main.scm @@ -6,31 +6,67 @@ (use-modules (srfi srfi-19) (srfi srfi-19 util) + (srfi srfi-26) + (ice-9 format) + (util) (vcalendar) (vcalendar output) - (util)) - -;;; This function borrowed from web-ics (calendar util) -(define* (sort* items comperator #:optional (get identity)) - "A sort function more in line with how python's sorted works" - (sort items (lambda (a b) - (comperator (get a) - (get b))))) + (terminal escape) + (terminal util)) ;;; ------------------------------------------------------------ +#; (define pizza-event (search cal "pizza")) + + +(define-public (event-in? ev time) + (in-day? (time-utc->date time) + (attr ev 'DTSTART))) + +(define (main-loop calendars) + (define time (date->time-utc (current-date))) + (let loop ((char #\nul)) + + (case char + ((#\L #\l) (set! time (add-day time))) + ((#\h #\H) (set! time (remove-day time)))) + + (cls) + (display-calendar-header! (time-utc->date time)) + (line) + + (let ((events + (sort* (concat + (map (lambda (cal) + (filter (cut event-in? <> time) + (children cal 'VEVENT))) + calendars)) + timestring (attr ev 'DTSTART) "~1 ~3") ; TODO show truncated string + (string-pad-right (attr ev 'SUMMARY) 30) ; TODO show truncated string + (or (attr ev 'LOCATION) "[INGEN LOKAL]") + STR-RESET)))) + + ;; (format #t "c = ~c (~d)~%" char (char->integer char)) + + (unless (or (eof-object? char) + (memv char (list #\q (ctrl #\C)))) + (loop (read-char (current-input-port)))))) + +(load "config.scm") + (define (main args) - (define path (cadr (append args '("testcal/repeating-event.ics")))) - (define cal (make-vcomponent path)) - ;; Sort the events, and print a simple agenda. - (for-each-in (sort* (children cal 'VEVENT) - timestring start "~1 ~H:~M"))) - (attr ev "SUMMARY"))))) + (define calendars (map make-vcomponent calendar-files)) + + (display calendar-files) (newline) + + (with-vulgar + (lambda () (main-loop calendars)))) - #; (define pizza-event (search cal "pizza")) -- cgit v1.2.3