Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Apr 10, 2020
1 parent 58df314 commit b47ea7b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 138 deletions.
95 changes: 0 additions & 95 deletions pkg/commands/exec_live_default.go

This file was deleted.

9 changes: 0 additions & 9 deletions pkg/commands/exec_live_win.go

This file was deleted.

31 changes: 0 additions & 31 deletions pkg/commands/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"sync"

Expand Down Expand Up @@ -117,36 +116,6 @@ func (c *OSCommand) ExecutableFromString(commandStr string) *exec.Cmd {
return cmd
}

// RunCommandWithOutputLive runs RunCommandWithOutputLiveWrapper
func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string) string) error {
return RunCommandWithOutputLiveWrapper(c, command, output)
}

// DetectUnamePass detect a username / password question in a command
// ask is a function that gets executen when this function detect you need to fillin a password
// The ask argument will be "username" or "password" and expects the user's password or username back
func (c *OSCommand) DetectUnamePass(command string, ask func(string) string) error {
ttyText := ""
errMessage := c.RunCommandWithOutputLive(command, func(word string) string {
ttyText = ttyText + " " + word

prompts := map[string]string{
"password": `Password\s*for\s*'.+':`,
"username": `Username\s*for\s*'.+':`,
}

for askFor, pattern := range prompts {
if match, _ := regexp.MatchString(pattern, ttyText); match {
ttyText = ""
return ask(askFor)
}
}

return ""
})
return errMessage
}

// RunCommand runs a command and just returns the error
func (c *OSCommand) RunCommand(formatString string, formatArgs ...interface{}) error {
_, err := c.RunCommandWithOutput(formatString, formatArgs...)
Expand Down
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:
prevScreenMode: '_'
undo: 'z'
redo: '<c-z>'
install: 'i'
cleanInstall: 'I'
status:
checkForUpdate: 'u'
main:
Expand Down
11 changes: 11 additions & 0 deletions pkg/gui/dependencies_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ func (gui *Gui) handleDepSelect(g *gocui.Gui, v *gocui.View) error {
}
return nil
}

// linkPathMap returns the set of link paths of the current package's dependencies
func (gui *Gui) linkPathMap() map[string]bool {
linkPathMap := map[string]bool{}
for _, dep := range gui.State.Deps {
if dep.Linked() {
linkPathMap[dep.LinkPath] = true
}
}
return linkPathMap
}
6 changes: 6 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Modifier: gocui.ModNone,
Handler: gui.handleLinkPackage,
},
{
ViewName: "",
Key: gui.getKey("universal.install"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleInstall),
},
}

for _, viewName := range []string{"status", "packages", "deps", "scripts", "menu"} {
Expand Down
22 changes: 19 additions & 3 deletions pkg/gui/packages_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,31 @@ func (gui *Gui) handleLinkPackage(g *gocui.Gui, v *gocui.View) error {

var cmdStr string
if selectedPkg == currentPkg {
cmdStr = "npm link"
if gui.linkPathMap()[selectedPkg.Path] {
cmdStr = "npm unlink"
} else {
cmdStr = "npm link"
}
} else {
cmdStr = fmt.Sprintf("npm link %s", selectedPkg.Config.Name)
if gui.linkPathMap()[selectedPkg.Path] {
cmdStr = fmt.Sprintf("npm unlink --no-save %s", selectedPkg.Config.Name)
} else {
cmdStr = fmt.Sprintf("npm link %s", selectedPkg.Config.Name)
}
}

cmd := gui.OSCommand.ExecutableFromString(cmdStr)
if err := gui.newCmdTask("main", cmd); err != nil {
if err := gui.newPtyTask("main", cmd); err != nil {
gui.Log.Error(err)
}

return nil
}

func (gui *Gui) handleInstall() error {
cmd := gui.OSCommand.ExecutableFromString("npm install")
if err := gui.newPtyTask("main", cmd); err != nil {
gui.Log.Error(err)
}
return nil
}

0 comments on commit b47ea7b

Please # to comment.