From c9b516afd587050f3424149cfe226f0945378a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 23 Apr 2019 22:51:47 +0200 Subject: Get terminal size of terminal output. --- module/output/terminal.scm | 7 ++++++- module/terminal/util.scm | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'module') diff --git a/module/output/terminal.scm b/module/output/terminal.scm index f9796d68..ebe1e483 100644 --- a/module/output/terminal.scm +++ b/module/output/terminal.scm @@ -48,6 +48,11 @@ (define (main-loop time event-stream) (define cur-event 0) + (define height 0) + (define width 0) + (let* ((h w (get-terminal-size))) + (set! height h + width w)) (while #t (let ((events @@ -73,7 +78,7 @@ (time->string (attr ev 'DTEND) "~1 ~3") (flow-text (or (attr ev 'DESCRIPTION) "") #:width 70 - #:height 10)))) + #:height (- height 8 2 (length events) 5))))) (let ((char (read-char))) ;; (format (current-error-port) diff --git a/module/terminal/util.scm b/module/terminal/util.scm index a7435ad8..f4d60fda 100644 --- a/module/terminal/util.scm +++ b/module/terminal/util.scm @@ -1,6 +1,8 @@ (define-module (terminal util) #:use-module (srfi srfi-19) #:use-module (srfi srfi-60) + #:use-module (util) + #:use-module (ice-9 popen) #:export (line ctrl color-escape)) (define* (line #:optional (width 64)) @@ -35,3 +37,10 @@ (string->number gs 16) (string->number bs 16)))))) + +(define-public (get-terminal-size) + (let* (((rpipe . wpipe) (pipe))) + (system (format #f "stty size > /proc/~s/fd/~s" + (getpid) (port->fdes wpipe))) + (values (read rpipe) + (read rpipe)))) -- cgit v1.2.3