Skip to content

Commit 6578d5e

Browse files
authored
compact mode for aat (#191)
compacts the table and hides cloud icons
1 parent 2127ad0 commit 6578d5e

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

frontends/ascii-art-table.go

+45-13
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import (
1818
type aatConfig struct {
1919
coords bool
2020
monochrome bool
21-
unit iface.UnitSystem
21+
compact bool
22+
23+
unit iface.UnitSystem
2224
}
2325

24-
//TODO: replace s parameter with printf interface?
26+
// TODO: replace s parameter with printf interface?
2527
func aatPad(s string, mustLen int) (ret string) {
2628
ansiEsc := regexp.MustCompile("\033.*?m")
2729
ret = s
@@ -283,9 +285,13 @@ func (c *aatConfig) formatCond(cur []string, cond iface.Cond, current bool) (ret
283285
},
284286
}
285287

286-
icon, ok := codes[cond.Code]
287-
if !ok {
288-
log.Fatalln("aat-frontend: The following weather code has no icon:", cond.Code)
288+
icon := make([]string, 5)
289+
if !c.compact {
290+
var ok bool
291+
icon, ok = codes[cond.Code]
292+
if !ok {
293+
log.Fatalln("aat-frontend: The following weather code has no icon:", cond.Code)
294+
}
289295
}
290296

291297
desc := cond.Desc
@@ -352,19 +358,45 @@ func (c *aatConfig) printDay(day iface.Day) (ret []string) {
352358
}
353359

354360
dateFmt := "┤ " + day.Date.Format("Mon 02. Jan") + " ├"
355-
ret = append([]string{
356-
" ┌─────────────┐ ",
357-
"┌──────────────────────────────┬───────────────────────" + dateFmt + "───────────────────────┬──────────────────────────────┐",
358-
"│ Morning │ Noon └──────┬──────┘ Evening │ Night │",
359-
"├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤"},
360-
ret...)
361-
return append(ret,
362-
"└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘")
361+
if !c.compact {
362+
ret = append([]string{
363+
" ┌─────────────┐ ",
364+
"┌──────────────────────────────┬───────────────────────" + dateFmt + "───────────────────────┬──────────────────────────────┐",
365+
"│ Morning │ Noon └──────┬──────┘ Evening │ Night │",
366+
"├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤"},
367+
ret...)
368+
ret = append(ret,
369+
"└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘")
370+
} else {
371+
merge := func(src string, into string) string {
372+
ret := []rune(into)
373+
for k, v := range src {
374+
ret[k] = v
375+
}
376+
return string(ret)
377+
}
378+
379+
spaces := (len(ret[0]) / 4) - 3
380+
bar := strings.Repeat("─", spaces)
381+
382+
ret = append([]string{
383+
day.Date.Format("Mon 02. Jan"),
384+
"┌" + merge("Morning", bar) + "┬" + merge("Noon", bar) + "┬" + merge("Evening", bar) + "┬" + merge("Night", bar) + "┐",
385+
}, ret...)
386+
387+
ret = append(ret,
388+
"└"+bar+"┴"+bar+"┴"+bar+"┴"+bar+"┘",
389+
)
390+
}
391+
392+
return ret
363393
}
364394

365395
func (c *aatConfig) Setup() {
366396
flag.BoolVar(&c.coords, "aat-coords", false, "aat-frontend: Show geo coordinates")
367397
flag.BoolVar(&c.monochrome, "aat-monochrome", false, "aat-frontend: Monochrome output")
398+
399+
flag.BoolVar(&c.compact, "aat-compact", false, "aat-frontend: Compact output")
368400
}
369401

370402
func (c *aatConfig) Render(r iface.Data, unitSystem iface.UnitSystem) {

0 commit comments

Comments
 (0)