Skip to content

Commit

Permalink
color based on semver constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Apr 11, 2020
1 parent 3656a37 commit 4fa5903
Show file tree
Hide file tree
Showing 19 changed files with 1,430 additions and 338 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/jesseduffield/lazynpm
go 1.14

require (
github.com/Masterminds/semver v1.5.0
github.com/buger/jsonparser v0.0.0-20200322175846-f7e751efca13
github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
github.com/creack/pty v1.1.10-0.20191209115840-8ab47f72e854
Expand All @@ -16,7 +17,7 @@ require (
github.com/integrii/flaggy v1.4.0
github.com/jesseduffield/gocui v0.3.1-0.20200405034337-066b5b6ca1ba
github.com/jesseduffield/termbox-go v0.0.0-20200405031649-4dc645f7e8ba // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.0/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
Expand Down
25 changes: 24 additions & 1 deletion pkg/gui/presentation/dependencies.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package presentation

import (
"github.com/Masterminds/semver"
"github.com/fatih/color"
"github.com/jesseduffield/lazynpm/pkg/commands"
"github.com/jesseduffield/lazynpm/pkg/utils"
Expand All @@ -22,8 +23,30 @@ func getDepDisplayStrings(d *commands.Dependency) []string {
if d.Linked() {
localVersionCol = utils.ColoredString("linked: "+d.LinkPath, color.FgCyan)
} else if d.PackageConfig != nil {
localVersionCol = utils.ColoredString(d.PackageConfig.Version, color.FgYellow)
attr := color.FgYellow
if semverGood(d.PackageConfig.Version, d.Version) {
attr = color.FgGreen
}
localVersionCol = utils.ColoredString(d.PackageConfig.Version, attr)
} else {
localVersionCol = utils.ColoredString("missing", color.FgRed)
}

return []string{d.Name, utils.ColoredString(d.Version, color.FgMagenta), localVersionCol}
}

func semverGood(version, constraint string) bool {
c, err := semver.NewConstraint(constraint)
if err != nil {
return false
}

v, err := semver.NewVersion(version)
if err != nil {
return false
}

a := c.Check(v)

return a
}
109 changes: 109 additions & 0 deletions vendor/github.com/Masterminds/semver/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/Masterminds/semver/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions vendor/github.com/Masterminds/semver/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4fa5903

Please # to comment.