diff --git a/go.mod b/go.mod index f887c6e..b3f633d 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,13 @@ module go.jolheiser.com/caniuse go 1.19 -require github.com/peterbourgon/ff/v3 v3.3.0 +require ( + github.com/fatih/color v1.13.0 + github.com/peterbourgon/ff/v3 v3.3.0 +) + +require ( + github.com/mattn/go-colorable v0.1.9 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect +) diff --git a/go.sum b/go.sum index bdc8b56..2bb9038 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,13 @@ +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/peterbourgon/ff/v3 v3.3.0 h1:PaKe7GW8orVFh8Unb5jNHS+JZBwWUMa2se0HM6/BI24= github.com/peterbourgon/ff/v3 v3.3.0/go.mod h1:zjJVUhx+twciwfDl0zBcFzl4dW8axCRyXE/eKY9RztQ= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/main.go b/main.go index c35bd90..09c816b 100644 --- a/main.go +++ b/main.go @@ -7,8 +7,10 @@ import ( "io/fs" "os" "path/filepath" + "strings" "time" + "github.com/fatih/color" "github.com/peterbourgon/ff/v3" ) @@ -47,6 +49,17 @@ func main() { fmt.Println(data) } +func showFeat(d data) { + var p []string + if d.UsagePercY > 0 { + p = append(p, fmt.Sprintf("%s %s%%", resultmap["y"], color.GreenString("%f", d.UsagePercY))) + } + if d.UsagePercA > 0 { + p = append(p, fmt.Sprintf("%s %s%%", resultmap["a"], color.YellowString("%f", d.UsagePercA))) + } + percentages := strings.Join(p, " ") +} + func loadData() (Data, error) { var data Data diff --git a/struct.go b/struct.go index b409bad..3ffe05a 100644 --- a/struct.go +++ b/struct.go @@ -21,29 +21,7 @@ type Data struct { Unoff string `json:"unoff"` } `json:"statuses"` Cats map[string][]string `json:"cats"` - Data map[string]struct { - Title string `json:"title"` - Description string `json:"description"` - Spec string `json:"spec"` - Status string `json:"status"` - Links []struct { - URL string `json:"url"` - Title string `json:"title"` - } `json:"links"` - Categories []string `json:"categories"` - Stats map[string]map[string]stat `json:"stats"` - Notes string `json:"notes"` - NotesByNum map[string]string `json:"notes_by_num"` - UsagePercY float64 `json:"usage_perc_y"` - UsagePercA float64 `json:"usage_perc_a"` - UCPrefix bool `json:"ucprefix"` - Parent string `json:"parent"` - Keywords string `json:"keywords"` - IEID string `json:"ie_id"` - ChromeID string `json:"chrome_id"` - FirefoxID string `json:"firefox_id"` - WebkitID string `json:"webkit_id"` - } `json:"data"` + Data map[string]data `json:"data"` } type stat string @@ -51,3 +29,27 @@ type stat string func (s stat) Bool() bool { return s == "y" } + +type data struct { + Title string `json:"title"` + Description string `json:"description"` + Spec string `json:"spec"` + Status string `json:"status"` + Links []struct { + URL string `json:"url"` + Title string `json:"title"` + } `json:"links"` + Categories []string `json:"categories"` + Stats map[string]map[string]stat `json:"stats"` + Notes string `json:"notes"` + NotesByNum map[string]string `json:"notes_by_num"` + UsagePercY float64 `json:"usage_perc_y"` + UsagePercA float64 `json:"usage_perc_a"` + UCPrefix bool `json:"ucprefix"` + Parent string `json:"parent"` + Keywords string `json:"keywords"` + IEID string `json:"ie_id"` + ChromeID string `json:"chrome_id"` + FirefoxID string `json:"firefox_id"` + WebkitID string `json:"webkit_id"` +}