From 9c46c0c552cda4fd4a87979f8f8afa363900bcc5 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Sat, 10 Sep 2022 21:34:18 +0200 Subject: [PATCH] Automatically adjust table width --- sncf.ss | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sncf.ss b/sncf.ss index 534349c..122e7ad 100755 --- a/sncf.ss +++ b/sncf.ss @@ -39,6 +39,7 @@ (get-station-id sncf-key station) (values "Vernon - Giverny (Vernon)" "stop_area:SNCF:87415604"))) (let-values (((departures disruptions) (get-departures sncf-key station-id))) + (displayln (compute-table-widths departures)) (displayln (str "Station : " station-name)) (display-departures-table departures) (display-disruptions disruptions) @@ -94,10 +95,18 @@ base-dep-dt dep-dt)))) +(def (compute-table-widths departures) + (def widths + (for/collect ((dep departures)) + (with ((departure network direction _ _) dep) + (list (string-length network) (string-length direction))))) + (apply map max widths)) + (def (display-departures-table departures style: (style 'unicode)) (def good-emoji (if (eq? style 'markdown) ":white_check_mark: " "")) (def bad-emoji (if (eq? style 'markdown) ":warning: " "")) - (def tab (table '("Réseau" "Direction" "Heure") [15 60 (if (eq? style 'markdown) 32 13)] style)) + (def widths (compute-table-widths departures)) + (def tab (table '("Réseau" "Direction" "Heure") [(map max '(5 9) widths) ... (if (eq? style 'markdown) 32 13)] style)) (display (table-header tab)) (for ((dep departures)) (with ((departure network direction base-dep-dt dep-dt) dep)