aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-03-19 00:13:51 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-03-19 00:18:14 +0100
commitfd1bc1f4183ed9a8248f30a25ef7662afba1b4db (patch)
tree30d1cc5150cffafc2e5b1e4371b94827a3eb634d
parentFix BSD cal output. (diff)
downloadcalp-fd1bc1f4183ed9a8248f30a25ef7662afba1b4db.tar.gz
calp-fd1bc1f4183ed9a8248f30a25ef7662afba1b4db.tar.xz
Add simple event view to vulgar front-end.
-rwxr-xr-xmain.scm49
1 files changed, 42 insertions, 7 deletions
diff --git a/main.scm b/main.scm
index 29686375..3850a470 100755
--- a/main.scm
+++ b/main.scm
@@ -4,16 +4,23 @@
(add-to-load-path (dirname (current-filename)))
-(use-modules (srfi srfi-19)
+(use-modules (srfi srfi-1)
+ (srfi srfi-19)
(srfi srfi-19 util)
(srfi srfi-26)
(ice-9 format)
+ (texinfo string-utils) ; string->wrapped-lines
(util)
(vcalendar)
(vcalendar output)
(terminal escape)
(terminal util))
+(define (take-to lst i)
+ (if (> i (length lst))
+ lst (take lst i)))
+
+
;;; ------------------------------------------------------------
#; (define pizza-event (search cal "pizza"))
@@ -67,11 +74,14 @@ Event must have the DTSTART and DTEND attribute set."
(define (main-loop calendars)
(define time (date->time-utc (current-date)))
+ (define cur-event 0)
(let loop ((char #\nul))
(case char
- ((#\L #\l) (set! time (add-day time)))
- ((#\h #\H) (set! time (remove-day time))))
+ ((#\L #\l) (set! time (add-day time)) (set! cur-event 0))
+ ((#\h #\H) (set! time (remove-day time)) (set! cur-event 0))
+ ((#\j #\J) (set! cur-event (1+ cur-event)))
+ ((#\k #\K) (unless (zero? cur-event) (set! cur-event (1- cur-event)))) )
(cls)
(display-calendar-header! (time-utc->date time))
@@ -89,14 +99,39 @@ Event must have the DTSTART and DTEND attribute set."
calendars))
time<? (extract "DTSTART"))))
- (for-each-in events
- (lambda (ev)
- (format #t "~a │ ~a~a~a │ ~a~%"
+ (for-each
+ (lambda (ev i)
+ (format #t "~a │ ~a~a~a~a │ ~a~a~%"
(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)
STR-RESET
- (trim-to-width (or (attr ev 'LOCATION) "[INGEN LOKAL]") 20)))))
+ (trim-to-width
+ (or (attr ev 'LOCATION) "\x1b[1;30mINGEN LOKAL") 20)
+ STR-RESET))
+ events
+ (iota (length events)))
+
+ (format #t "~a┴~a┴~a~%"
+ (make-string 20 #\─)
+ (make-string 32 #\─)
+ (make-string 10 #\─))
+
+ (let ((ev (list-ref events cur-event)))
+ (format #t "~a~%~aStart: ~a Slut: ~a~%~%~a~%"
+ (attr ev 'SUMMARY)
+ (or (and=> (attr ev 'LOCATION) (cut string-append "Plats: " <> "\n")) "")
+ (time->string (attr ev 'DTSTART) "~1 ~3")
+ (time->string (attr ev 'DTEND) "~1 ~3")
+ (string-join ; TODO replace this with a better text flower
+ (take-to ; This one destroys newlines used for layout
+ (string->wrapped-lines (or (attr ev 'DESCRIPTION) "")
+ #:line-width 60
+ #:collapse-whitespace? #f)
+ 10)
+ (string #\newline))
+ )))
;; (format #t "c = ~c (~d)~%" char (char->integer char))