From 0279f9b45c7eb0a85da79f8083fb65da18e4ff55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 28 Jun 2020 23:31:29 +0200 Subject: Add describe procedure for vcomponents. --- module/vcomponent/describe.scm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 module/vcomponent/describe.scm (limited to 'module/vcomponent') diff --git a/module/vcomponent/describe.scm b/module/vcomponent/describe.scm new file mode 100644 index 00000000..4e89f5e8 --- /dev/null +++ b/module/vcomponent/describe.scm @@ -0,0 +1,33 @@ +(define-module (vcomponent describe) + :use-module (util) + :use-module (vcomponent base) + :use-module (text util)) + +(define*-public (describe vcomponent optional: (indent 0)) + (define ii (make-string indent #\space)) + (define iii (make-string (1+ indent) #\space)) + + (define maxlen (find-max (hash-map->list + (lambda (a _) (string-length (symbol->string a))) + (attributes vcomponent)))) + + (format #t "~aBEGIN ~a~%" ii (type vcomponent)) + + (hash-for-each (lambda (key vline) + (format #t "~a~a = ~a" + iii + (trim-to-width (symbol->string key) maxlen) + (trim-to-width + (format #f "~a" (value vline)) + (- 80 indent maxlen))) + (awhen (properties vline) + (display " ;") + (for (key value) in it + (format #t " ~a=~a" key value))) + (newline)) + (attributes vcomponent)) + + (for child in (children vcomponent) + (describe child (+ indent 2))) + + (format #t "~aEND ~a~%" ii (type vcomponent))) -- cgit v1.2.3