Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Apr 11, 2020
1 parent f119ee6 commit be54d40
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
10 changes: 9 additions & 1 deletion pkg/gui/dependencies_panel.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package gui

import (
"fmt"

"github.com/fatih/color"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazynpm/pkg/commands"
"github.com/jesseduffield/lazynpm/pkg/gui/presentation"
"github.com/jesseduffield/lazynpm/pkg/utils"
)

// list panel functions
Expand All @@ -22,7 +26,11 @@ func (gui *Gui) handleDepSelect(g *gocui.Gui, v *gocui.View) error {
return gui.newStringTask("main", gui.Tr.SLocalize("NoDependencies"))
}
if dep.PackageConfig != nil {
gui.renderString("secondary", presentation.PackageSummary(*dep.PackageConfig))
summary := presentation.PackageSummary(*dep.PackageConfig)
if dep.Linked() {
summary = fmt.Sprintf("%s\nLinked to: %s", summary, utils.ColoredString(dep.LinkPath, color.FgCyan))
}
gui.renderString("secondary", summary)
} else {
gui.renderString("secondary", "dependency not present in node_modules")
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/gui/packages_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package gui
import (
"fmt"

"github.com/fatih/color"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazynpm/pkg/commands"
"github.com/jesseduffield/lazynpm/pkg/gui/presentation"
"github.com/jesseduffield/lazynpm/pkg/utils"
)

// list panel functions
Expand All @@ -23,7 +25,9 @@ func (gui *Gui) handlePackageSelect(g *gocui.Gui, v *gocui.View) error {
gui.getMainView().Title = ""
return gui.newStringTask("main", gui.Tr.SLocalize("NoChangedPackages"))
}
gui.renderString("secondary", presentation.PackageSummary(pkg.Config))
summary := presentation.PackageSummary(pkg.Config)
summary = fmt.Sprintf("%s\nPath: %s", summary, utils.ColoredString(pkg.Path, color.FgCyan))
gui.renderString("secondary", summary)
return nil
}

Expand All @@ -38,7 +42,7 @@ func (gui *Gui) refreshPackages() error {
}

gui.g.Update(func(g *gocui.Gui) error {
displayStrings := presentation.GetPackageListDisplayStrings(gui.State.Packages, gui.State.Deps)
displayStrings := presentation.GetPackageListDisplayStrings(gui.State.Packages, gui.linkPathMap())
gui.renderDisplayStrings(packagesView, displayStrings)

displayStrings = presentation.GetDependencyListDisplayStrings(gui.State.Deps)
Expand Down
10 changes: 1 addition & 9 deletions pkg/gui/presentation/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@ import (
"github.com/jesseduffield/lazynpm/pkg/utils"
)

func GetPackageListDisplayStrings(packages []*commands.Package, deps []*commands.Dependency) [][]string {
func GetPackageListDisplayStrings(packages []*commands.Package, linkPathMap map[string]bool) [][]string {
lines := make([][]string, len(packages))

// we need to work out all the link paths from the deps
linkPathMap := map[string]bool{}
for _, dep := range deps {
if dep.Linked() {
linkPathMap[dep.LinkPath] = true
}
}

for i := range packages {
pkg := packages[i]
lines[i] = getPackageDisplayStrings(pkg, linkPathMap[pkg.Path])
Expand Down

0 comments on commit be54d40

Please # to comment.