Skip to content

Commit

Permalink
more progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Apr 12, 2020
1 parent 453ad90 commit 7fec596
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 15 deletions.
2 changes: 2 additions & 0 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ keybinding:
build: 'b'
pack: 'p'
publish: 'P'
dependencies:
changeType: 't'
`)
}

Expand Down
29 changes: 29 additions & 0 deletions pkg/gui/dependencies_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,32 @@ func (gui *Gui) wrappedDependencyHandler(f func(*commands.Dependency) error) fun
return f(dep)
})
}

func (gui *Gui) handleChangeDepType(dep *commands.Dependency) error {
installProd := "npm install --save-prod"
installDev := "npm install --save-dev"
installOptional := "npm install --save-optional"

menuItems := []*menuItem{
{
displayStrings: []string{"dependencies", utils.ColoredString(installProd, color.FgYellow)},
onPress: func() error {
return gui.newMainCommand(installProd, dep.ID())
},
},
{
displayStrings: []string{"devDependencies", utils.ColoredString(installDev, color.FgYellow)},
onPress: func() error {
return gui.newMainCommand(installDev, dep.ID())
},
},
{
displayStrings: []string{"optionalDependencies", utils.ColoredString(installOptional, color.FgYellow)},
onPress: func() error {
return gui.newMainCommand(installOptional, dep.ID())
},
},
}

return gui.createMenu("Change dependency type", menuItems, createMenuOptions{showCancel: true})
}
33 changes: 19 additions & 14 deletions pkg/gui/global_handlers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gui

import (
"math"
"os/exec"

"github.com/jesseduffield/gocui"
Expand All @@ -21,26 +20,32 @@ func (gui *Gui) prevScreenMode(g *gocui.Gui, v *gocui.View) error {
}

func (gui *Gui) scrollUpView(viewName string) error {
mainView, _ := gui.g.View(viewName)
ox, oy := mainView.Origin()
newOy := int(math.Max(0, float64(oy-gui.Config.GetUserConfig().GetInt("gui.scrollHeight"))))
return mainView.SetOrigin(ox, newOy)
view, _ := gui.g.View(viewName)
view.Autoscroll = false
ox, oy := view.Origin()
scrollHeight := gui.Config.GetUserConfig().GetInt("gui.scrollHeight")
newOy := oy - scrollHeight
if newOy <= 0 {
newOy = 0
}
return view.SetOrigin(ox, newOy)
}

func (gui *Gui) scrollDownView(viewName string) error {
mainView, _ := gui.g.View(viewName)
ox, oy := mainView.Origin()
y := oy
if !gui.Config.GetUserConfig().GetBool("gui.scrollPastBottom") {
_, sy := mainView.Size()
y += sy
}
view, _ := gui.g.View(viewName)
view.Autoscroll = false
ox, oy := view.Origin()
_, sy := view.Size()
y := oy + sy
scrollHeight := gui.Config.GetUserConfig().GetInt("gui.scrollHeight")
if y < mainView.LinesHeight() {
if err := mainView.SetOrigin(ox, oy+scrollHeight); err != nil {
if y < view.LinesHeight()-1 {
if err := view.SetOrigin(ox, oy+scrollHeight); err != nil {
return err
}
} else {
view.Autoscroll = true
}

return nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.wrappedDependencyHandler(gui.handleDepUninstall),
Description: fmt.Sprintf("%s dependency", utils.ColoredString("`npm uninstall`", color.FgYellow)),
},
{
ViewName: "deps",
Key: gui.getKey("dependencies.changeType"),
Handler: gui.wrappedDependencyHandler(gui.handleChangeDepType),
Description: "change dependency type (prod/dev/optional)",
},
}

for _, viewName := range []string{"status", "packages", "deps", "scripts", "menu"} {
Expand Down
4 changes: 3 additions & 1 deletion pkg/gui/tasks_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func (gui *Gui) newMainCommand(cmdStr string, contextKey string) error {
}
v.Wrap = true
v.FgColor = theme.GocuiDefaultTextColor
v.Autoscroll = true

bindings := []*Binding{
{
Expand Down Expand Up @@ -61,6 +60,9 @@ func (gui *Gui) newMainCommand(cmdStr string, contextKey string) error {
}
}

// autoscroll might have been turned off if the user scrolled midway through the last command
v.Autoscroll = true

if _, err := gui.g.SetViewOnTop(contextKey); err != nil {
return err
}
Expand Down

0 comments on commit 7fec596

Please sign in to comment.