From e574ac6251567732c218afaeeade92586a310022 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Sat, 10 Sep 2022 21:51:02 +0200 Subject: [PATCH] Add styling to output --- sncf.ss | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sncf.ss b/sncf.ss index 46aa352..da9b0cd 100755 --- a/sncf.ss +++ b/sncf.ss @@ -11,6 +11,7 @@ :std/srfi/19 :std/sugar :std/text/json + :dlozeve/fancy/format :dlozeve/fancy/table) (def +sncf-url+ "https://api.sncf.com/v1/coverage/sncf") @@ -39,11 +40,12 @@ (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 (str "Prochains départs de " station-name)) + (displayln (parse-markup (format "[bold]Prochains départs de [green]~a[/green] :" station-name))) (display-departures-table departures) (display-disruptions disruptions) (when mattermost-url (let ((tab-str-md (with-output-to-string (lambda () + (displayln (format "Prochains départs de **~a** :" station-name)) (display-departures-table departures style: 'markdown) (display-disruptions disruptions style: 'markdown))))) (post-to-mattermost mattermost-url tab-str-md channel: mattermost-channel))))) @@ -103,9 +105,12 @@ (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 bad-emoji (if (eq? style 'markdown) ":warning: " "[yellow]")) (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)) + (def headers (if (eq? style 'markdown) + '("Réseau" "Direction" "Heure") + '("[bold]Réseau" "[bold]Direction" "[bold]Heure"))) + (def tab (table headers [(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) @@ -119,15 +124,11 @@ (def (display-disruptions disruptions style: (style 'unicode)) (unless (null? disruptions) - (displayln "Perturbations :")) + (displayln (if (eq? style 'markdown) "**Perturbations :**" (parse-markup "[bold]Perturbations :")))) (for ((dis disruptions)) (let ((messages (hash-ref dis 'messages '()))) - (if (eq? style 'markdown) - (display "* ") - (display "• ")) - (if (null? messages) - (displayln "[Pas de message]") - (displayln (hash-ref (car messages) 'text)))))) + (display (if (eq? style 'markdown) "* " "• ")) + (displayln (if (null? messages) "[Pas de message]" (hash-ref (car messages) 'text)))))) (def (post-to-mattermost url text channel: (channel #f)) (def data (list->hash-table `((text . ,text))))