(use-modules (ice-9 match) (ice-9 popen)) (format #t "~a~%" (let ((in (open-pipe* OPEN_READ "/gnu/store/2n96ak0dkkbv3kijfi3dxrrxz8pkj0d1-v86d-0.1.10-testvbe/sbin/testvbe"))) (define (skip-head) "Skip head of testvbe output." (let ((line ((@ (ice-9 textual-ports) get-line) in))) (cond ((eof-object? line) (error "Invalid testvbe output.")) ((string=? "---------------------------" line) #t) (else (skip-head))))) (define (line->resolution line) "Return a list of the horizontal and vertical resolution given in a LINE of testvbe output. The return value is a list of two exact integers." (match (filter (lambda (str) (not (string-null? str))) (string-split line char-set:blank)) ((_ _ res _) (map string->number (list-head (string-split res (char-set #\x #\-)) 2))))) (begin (skip-head) (let loop ((best (list 800 600))) (let ((line ((@ (ice-9 textual-ports) get-line) in))) (if (eof-object? line) (let ((best-string (map number->string best))) (match best-string ((horiz vert) (string-append horiz "x" vert)))) (let ((current (line->resolution line))) (loop (if (> (apply * current) (apply * best)) current best)))))))))