aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@hornquist.se>2019-04-23 23:09:40 +0200
committerHugo Hörnquist <hugo@hornquist.se>2019-04-23 23:09:40 +0200
commitb3bd7213146cc5b2c0d5070a2f3c592778c96fae (patch)
tree9c8c3c00ec5a609f062ab76f8f57ca171203d190
parentGet terminal size of terminal output. (diff)
downloadcalp-b3bd7213146cc5b2c0d5070a2f3c592778c96fae.tar.gz
calp-b3bd7213146cc5b2c0d5070a2f3c592778c96fae.tar.xz
Term display now reacts more to terminal size.
-rw-r--r--module/output/terminal.scm29
1 files changed, 21 insertions, 8 deletions
diff --git a/module/output/terminal.scm b/module/output/terminal.scm
index ebe1e483..2b04c7c6 100644
--- a/module/output/terminal.scm
+++ b/module/output/terminal.scm
@@ -26,18 +26,22 @@
(reduce (lambda (str done) (string-append done (string intersection) str))
"" (map (cut make-string <> line) lengths)))
-(define (display-event-table cur-event events)
+(define* (display-event-table events #:key
+ (cur-event -1)
+ (summary-width 30)
+ (location-width 20))
(for-each
(lambda (ev i)
- (format #t "~a │ ~a~a~a~a │ ~a~a~%"
+ (format #t "~a │ ~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))
;; Summary filter is a hook for the user
- (trim-to-width ((summary-filter) ev (attr ev 'SUMMARY)) 30)
+ (trim-to-width ((summary-filter) ev (attr ev 'SUMMARY)) summary-width)
STR-RESET
+ (if (attr ev 'LOCATION) "" "\x1b[1;30m")
(trim-to-width
- (or (attr ev 'LOCATION) "\x1b[1;30mINGEN LOKAL") 20)
+ (or (attr ev 'LOCATION) "INGEN LOKAL") location-width)
STR-RESET))
events
(iota (length events))))
@@ -64,9 +68,18 @@
(cls)
(display-calendar-header! (time-utc->date time))
- (displayln (box-top #\┬ #\─ 20 32 10))
- (display-event-table cur-event events)
- (displayln (box-top #\┴ #\─ 20 32 10))
+ (let* ((date-width 20)
+ (location-width 15)
+ (summary-width (- width date-width location-width 6)))
+ (displayln
+ (box-top #\┬ #\─ date-width (+ summary-width 2) (1+ location-width)))
+ (display-event-table
+ events
+ #:cur-event cur-event
+ #:location-width location-width
+ #:summary-width summary-width)
+ (displayln
+ (box-top #\┴ #\─ date-width (+ summary-width 2) (1+ location-width))))
(unless (null? events)
(let ((ev (list-ref events cur-event)))
@@ -77,7 +90,7 @@
(time->string (attr ev 'DTSTART) "~1 ~3")
(time->string (attr ev 'DTEND) "~1 ~3")
(flow-text (or (attr ev 'DESCRIPTION) "")
- #:width 70
+ #:width (min 70 width)
#:height (- height 8 2 (length events) 5)))))
(let ((char (read-char)))