diff --git a/pkg/commands/dependency.go b/pkg/commands/dependency.go index b1fa190..67dd09b 100644 --- a/pkg/commands/dependency.go +++ b/pkg/commands/dependency.go @@ -58,6 +58,6 @@ func KindFlags() []KindFlag { } } -func (d *Dependency) kindKey() string { +func (d *Dependency) KindKey() string { return KindKeyMap()[d.Kind] } diff --git a/pkg/commands/npm_manager.go b/pkg/commands/npm_manager.go index 3f56b82..9f5f574 100644 --- a/pkg/commands/npm_manager.go +++ b/pkg/commands/npm_manager.go @@ -210,7 +210,7 @@ func (m *NpmManager) EditDepConstraint(dep *Dependency, packageJsonPath string, return err } - updatedConfig, err := jsonparser.Set(config, jsonStringValue(constraint), dep.kindKey(), dep.Name) + updatedConfig, err := jsonparser.Set(config, jsonStringValue(constraint), dep.KindKey(), dep.Name) if err != nil { return err } diff --git a/pkg/gui/dependencies_panel.go b/pkg/gui/dependencies_panel.go index 7a5e71b..60ed9fe 100644 --- a/pkg/gui/dependencies_panel.go +++ b/pkg/gui/dependencies_panel.go @@ -28,6 +28,8 @@ func (gui *Gui) handleDepSelect(g *gocui.Gui, v *gocui.View) error { } if dep.PackageConfig != nil { summary := presentation.PackageSummary(*dep.PackageConfig) + summary = fmt.Sprintf("%s\nConstraint: %s", summary, utils.ColoredString(dep.Constraint, color.FgMagenta)) + summary = fmt.Sprintf("%s\nType: %s", summary, utils.ColoredString(dep.KindKey(), presentation.KindColor(dep.Kind))) if dep.Linked() { summary = fmt.Sprintf("%s\nLinked to: %s", summary, utils.ColoredString(dep.LinkPath, color.FgCyan)) } diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index a8697df..bfd63cc 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -11,12 +11,16 @@ import ( func (gui *Gui) nextScreenMode(g *gocui.Gui, v *gocui.View) error { gui.State.ScreenMode = utils.NextIntInCycle([]int{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + gui.refreshListViews() + return nil } func (gui *Gui) prevScreenMode(g *gocui.Gui, v *gocui.View) error { gui.State.ScreenMode = utils.PrevIntInCycle([]int{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + gui.refreshListViews() + return nil } diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index 45e5254..3f3f1a6 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -118,26 +118,33 @@ func (gui *Gui) getViewHeights() map[string]int { return vHeights } -func (gui *Gui) getMainViewDimensions() (int, int, int, int, error) { - width, height := gui.g.Size() +func (gui *Gui) getLeftSideWidth() int { + width, _ := gui.g.Size() sidePanelWidthRatio := gui.Config.GetUserConfig().GetFloat64("gui.sidePanelWidth") - var leftSideWidth int switch gui.State.ScreenMode { case SCREEN_NORMAL: - leftSideWidth = int(float64(width) * sidePanelWidthRatio) + return int(float64(width) * sidePanelWidthRatio) case SCREEN_HALF: - leftSideWidth = width/2 - 2 + return width/2 - 2 case SCREEN_FULL: currentView := gui.g.CurrentView() if currentView != nil && currentView.Name() == "main" { - leftSideWidth = 0 + return 0 } else { - leftSideWidth = width - 1 + return width - 1 } } + return 0 +} + +func (gui *Gui) getMainViewDimensions() (int, int, int, int, error) { + width, height := gui.g.Size() + + leftSideWidth := gui.getLeftSideWidth() + mainPanelLeft := leftSideWidth + 1 mainPanelRight := width - 1 mainPanelTop := 6 diff --git a/pkg/gui/packages_panel.go b/pkg/gui/packages_panel.go index 2c21f03..34d75f6 100644 --- a/pkg/gui/packages_panel.go +++ b/pkg/gui/packages_panel.go @@ -60,10 +60,16 @@ func (gui *Gui) refreshPackages() error { return err } - displayStrings := presentation.GetPackageListDisplayStrings(gui.State.Packages, gui.linkPathMap(), gui.State.CommandViewMap) - gui.renderDisplayStrings(packagesView, displayStrings) + gui.refreshListViews() - displayStrings = presentation.GetDependencyListDisplayStrings(gui.State.Deps, gui.State.CommandViewMap) + return nil +} + +func (gui *Gui) refreshListViews() { + displayStrings := presentation.GetPackageListDisplayStrings(gui.State.Packages, gui.linkPathMap(), gui.State.CommandViewMap) + gui.renderDisplayStrings(gui.getPackagesView(), displayStrings) + + displayStrings = presentation.GetDependencyListDisplayStrings(gui.State.Deps, gui.State.CommandViewMap, gui.getLeftSideWidth() > 70) gui.renderDisplayStrings(gui.getDepsView(), displayStrings) displayStrings = presentation.GetScriptListDisplayStrings(gui.getScripts(), gui.State.CommandViewMap) @@ -73,8 +79,6 @@ func (gui *Gui) refreshPackages() error { gui.renderDisplayStrings(gui.getTarballsView(), displayStrings) gui.refreshStatus() - - return nil } func (gui *Gui) currentPackage() *commands.Package { diff --git a/pkg/gui/presentation/dependencies.go b/pkg/gui/presentation/dependencies.go index ec605d3..a6155e0 100644 --- a/pkg/gui/presentation/dependencies.go +++ b/pkg/gui/presentation/dependencies.go @@ -10,19 +10,18 @@ import ( "github.com/jesseduffield/semver/v3" ) -func GetDependencyListDisplayStrings(dependencies []*commands.Dependency, commandMap commands.CommandViewMap) [][]string { +func GetDependencyListDisplayStrings(dependencies []*commands.Dependency, commandMap commands.CommandViewMap, wide bool) [][]string { lines := make([][]string, len(dependencies)) for i := range dependencies { dep := dependencies[i] - lines[i] = getDepDisplayStrings(dep, commandMap[dep.ID()]) + lines[i] = getDepDisplayStrings(dep, commandMap[dep.ID()], wide) } return lines } -func getDepDisplayStrings(d *commands.Dependency, commandView *commands.CommandView) []string { - +func getDepDisplayStrings(d *commands.Dependency, commandView *commands.CommandView, wide bool) []string { localVersionCol := "" if d.Linked() { localVersionCol = utils.ColoredString("linked: "+d.LinkPath, color.FgCyan) @@ -37,14 +36,20 @@ func getDepDisplayStrings(d *commands.Dependency, commandView *commands.CommandV localVersionCol = utils.ColoredString("missing", color.FgRed) } - kindColorMap := map[string]color.Attribute{ - "prod": color.FgYellow, - "dev": color.FgGreen, - "peer": color.FgMagenta, - "optional": theme.DefaultTextColor, + return []string{ + commandView.Status(), + utils.ColoredString(truncateWithEllipsis(d.Name, 30, wide), KindColor(d.Kind)), + utils.ColoredString(truncateWithEllipsis(d.Constraint, 20, wide), color.FgMagenta), + localVersionCol, + } +} + +func truncateWithEllipsis(str string, limit int, wide bool) string { + if wide { + return str } - return []string{commandView.Status(), d.Name, utils.ColoredString(d.Kind, kindColorMap[d.Kind]), utils.ColoredString(d.Constraint, color.FgMagenta), localVersionCol} + return utils.TruncateWithEllipsis(str, limit) } func statusMap() map[int]string { @@ -73,3 +78,12 @@ func semverStatus(version, constraint string) (int, bool) { return status, status == semver.GOOD } + +func KindColor(kind string) color.Attribute { + return map[string]color.Attribute{ + "prod": theme.DefaultTextColor, + "dev": color.FgGreen, + "optional": color.FgCyan, + "peer": color.FgMagenta, + }[kind] +}