Automatically adjust table width
This commit is contained in:
parent
d3ec8a9f65
commit
9c46c0c552
1 changed files with 10 additions and 1 deletions
11
sncf.ss
11
sncf.ss
|
@ -39,6 +39,7 @@
|
||||||
(get-station-id sncf-key station)
|
(get-station-id sncf-key station)
|
||||||
(values "Vernon - Giverny (Vernon)" "stop_area:SNCF:87415604")))
|
(values "Vernon - Giverny (Vernon)" "stop_area:SNCF:87415604")))
|
||||||
(let-values (((departures disruptions) (get-departures sncf-key station-id)))
|
(let-values (((departures disruptions) (get-departures sncf-key station-id)))
|
||||||
|
(displayln (compute-table-widths departures))
|
||||||
(displayln (str "Station : " station-name))
|
(displayln (str "Station : " station-name))
|
||||||
(display-departures-table departures)
|
(display-departures-table departures)
|
||||||
(display-disruptions disruptions)
|
(display-disruptions disruptions)
|
||||||
|
@ -94,10 +95,18 @@
|
||||||
base-dep-dt
|
base-dep-dt
|
||||||
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 (display-departures-table departures style: (style 'unicode))
|
||||||
(def good-emoji (if (eq? style 'markdown) ":white_check_mark: " ""))
|
(def good-emoji (if (eq? style 'markdown) ":white_check_mark: " ""))
|
||||||
(def bad-emoji (if (eq? style 'markdown) ":warning: " ""))
|
(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))
|
(display (table-header tab))
|
||||||
(for ((dep departures))
|
(for ((dep departures))
|
||||||
(with ((departure network direction base-dep-dt dep-dt) dep)
|
(with ((departure network direction base-dep-dt dep-dt) dep)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue