summaryrefslogtreecommitdiffstats
path: root/tests/010/align-columns.txr
blob: 8ae2b7f58eacff886e4b27516f9d72fb85ad41fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@(collect)
@  (coll)@{item /[^$]+/}@(end)
@(end)
@; nc = number of columns
@; pi = padded items (data with row lengths equalized with empty strings)
@; cw = vector of max column widths
@; ce = center padding
@(bind nc @(apply (fun max) (mapcar (fun length) item)))
@(bind pi @(mapcar (lambda (row)
                     (append row (repeat '("") (- nc (length row)))))
                   item))
@(bind cw @(vector-list
             (mapcar (lambda (column)
                       (apply (fun max) (mapcar (fun length) column)))
                     ;; matrix transpose trick cols become rows:
                     (apply (fun mapcar) (cons (fun list) pi)))))
@(bind ns "")
@(output)
@  (repeat)
@    (rep :counter i)@{pi @[cw i]} @(end)
@  (end)
@  (repeat)
@    (rep :counter i)@{pi @(- [cw i])} @(end)
@  (end)
@  (repeat)
@    (rep :counter i)@\
     @{ns @(trunc (- [cw i] (length pi)) 2)}@\
     @{pi @(- [cw i] (trunc (- [cw i] (length pi)) 2))} @(end)
@  (end)
@(end)