Color stuff

This commit is contained in:
Zoe Moore
2022-06-28 16:49:26 -07:00
parent e80543d576
commit bc06c10eb8

28
bt.nim
View File

@@ -1,4 +1,4 @@
import std/[json, httpclient, sequtils]
import std/[json, httpclient, sequtils, strutils, times]
import strformat
import os
import terminal
@@ -18,21 +18,35 @@ proc formatEstimateMinutes(minutes: string): string =
else:
&"{minutes} mins"
proc lineColor(color: string): ForegroundColor =
case color.toLowerAscii():
of "blue": fgBlue
of "green": fgGreen
of "red": fgRed
of "yellow": fgYellow
of "orange": fgMagenta
else: fgDefault
proc formatDepartures(etd: JSONNode): string =
let name = etd["root"]["station"][0]["name"].getStr
let lines = etd["root"]["station"][0]["etd"]
styledEcho styleBright, name
styledEcho styleBright, name & " - " & now().format("H:mm")
let maxDestLength = lines.map(proc (line: JSONNode) = line["destination"].getStr.len).foldl(max(a,b), 1)
for line in lines:
let dest = line["destination"].getStr
let estimate = formatEstimateMinutes(line["estimate"][0]["minutes"].getStr)
let color = line["estimate"][0]["color"].getStr
var estimate = formatEstimateMinutes(line["estimate"][0]["minutes"].getStr)
echo &"{dest}\t\t{estimate}"
if len(line["estimate"]) > 1:
estimate = estimate & ", " & formatEstimateMinutes(line["estimate"][1]["minutes"].getStr)
styledEcho lineColor(color), &"{dest}\t\t{estimate}"
proc usage() =
echo """i
bt - bart times cli
echo """bt - bart times cli
usage: bt station [direction n or s]
"""