From e3011f0912e42fb1fbe3a9656db0fdeda2f83e94 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Mon, 10 Oct 2022 11:44:50 -0500 Subject: [PATCH] sort browsers Signed-off-by: jolheiser --- main.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 38af3d5..759d892 100644 --- a/main.go +++ b/main.go @@ -128,16 +128,23 @@ func formatFeat(feat data, d Data, short bool) string { } needNote := make(map[int]struct{}) - for browser, stats := range feat.Stats { + browsers := make([]string, 0, len(feat.Stats)) + for browser := range feat.Stats { if d.Agents[browser].Type != "desktop" { continue } + browsers = append(browsers, browser) + } + sort.Strings(browsers) + for _, browser := range browsers { + agent := d.Agents[browser] + stats := feat.Stats[browser] if !short { out.WriteString("\t") } - out.WriteString(d.Agents[browser].Browser + " ") + out.WriteString(agent.Browser + " ") - results := makeResults(d.Agents[browser], stats) + results := makeResults(agent, stats) if len(results) == 1 { results[0].version = "" } @@ -165,10 +172,10 @@ func formatFeat(feat data, d Data, short bool) string { if _, ok := needNote[n]; !ok { continue } - out.WriteString(fmt.Sprintf("\t\t%s%s\n", color.YellowString(supernums[n]), feat.NotesByNum[num])) + out.WriteString(fmt.Sprintf("\t%s%s\n", color.YellowString(supernums[n]), feat.NotesByNum[num])) } if feat.Notes != "" { - out.WriteString(fmt.Sprintf("\t %s %s", resultmap["i"], replaceNoteRe.ReplaceAllString(feat.Notes, " "))) + out.WriteString(fmt.Sprintf("\t%s %s", resultmap["i"], replaceNoteRe.ReplaceAllString(feat.Notes, " "))) } } @@ -206,7 +213,7 @@ func makeResult(stat browserStat, nums map[int]struct{}) string { } out.WriteString(fmt.Sprintf("(%f) ", math.Round(stat.usage*1)/1)) } - out.WriteString(" ") + out.WriteString(" ") str := out.String() switch support { @@ -276,6 +283,7 @@ func loadData() (Data, error) { if err != nil && !errors.Is(err, fs.ErrNotExist) { return data, fmt.Errorf("could not stat %q: %v", dataPath, err) } else if errors.Is(err, fs.ErrNotExist) || time.Since(fi.ModTime()) > refresh { + color.Blue("updating caniuse data...") if err := Download(dataPath); err != nil { return data, fmt.Errorf("could not download data: %v", err) }