Skip to content

Commit

Permalink
some more good progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Apr 12, 2020
1 parent 0b279a1 commit ce9cf9d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 65 deletions.
4 changes: 4 additions & 0 deletions pkg/commands/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,7 @@ func (p *Package) ConfigPath() string {
func (p *Package) ID() string {
return fmt.Sprintf("package:%s", p.Path)
}

func (p *Package) Scoped() bool {
return strings.HasPrefix(p.Config.Name, "@")
}
1 change: 1 addition & 0 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ keybinding:
globalLink: 'L'
build: 'b'
pack: 'p'
publish: 'P'
`)
}

Expand Down
84 changes: 21 additions & 63 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,344 +201,302 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
{
ViewName: "",
Key: gui.getKey("universal.quit"),
Modifier: gocui.ModNone,
Handler: gui.handleQuit,
},
{
ViewName: "",
Key: gui.getKey("universal.quitWithoutChangingDirectory"),
Modifier: gocui.ModNone,
Handler: gui.handleQuitWithoutChangingDirectory,
},
{
ViewName: "",
Key: gui.getKey("universal.quit-alt1"),
Modifier: gocui.ModNone,
Handler: gui.handleQuit,
},
{
ViewName: "",
Key: gui.getKey("universal.return"),
Modifier: gocui.ModNone,
Handler: gui.handleQuit,
},
{
ViewName: "",
Key: gui.getKey("universal.scrollUpMain"),
Modifier: gocui.ModNone,
Handler: gui.scrollUpMain,
Alternative: "fn+up",
Description: gui.Tr.SLocalize("scrollUpMainPanel"),
},
{
ViewName: "",
Key: gui.getKey("universal.scrollDownMain"),
Modifier: gocui.ModNone,
Handler: gui.scrollDownMain,
Alternative: "fn+down",
Description: gui.Tr.SLocalize("scrollDownMainPanel"),
},
{
ViewName: "",
Key: gui.getKey("universal.scrollUpMain-alt1"),
Modifier: gocui.ModNone,
Handler: gui.scrollUpMain,
},
{
ViewName: "",
Key: gui.getKey("universal.scrollDownMain-alt1"),
Modifier: gocui.ModNone,
Handler: gui.scrollDownMain,
},
{
ViewName: "",
Key: gui.getKey("universal.scrollUpMain-alt2"),
Modifier: gocui.ModNone,
Handler: gui.scrollUpMain,
},
{
ViewName: "",
Key: gui.getKey("universal.scrollDownMain-alt2"),
Modifier: gocui.ModNone,
Handler: gui.scrollDownMain,
},
{
ViewName: "",
Key: gui.getKey("universal.refresh"),
Modifier: gocui.ModNone,
Handler: gui.handleRefresh,
Description: gui.Tr.SLocalize("refresh"),
},
{
ViewName: "",
Key: gui.getKey("universal.optionMenu"),
Modifier: gocui.ModNone,
Handler: gui.handleCreateOptionsMenu,
Description: gui.Tr.SLocalize("openMenu"),
},
{
ViewName: "",
Key: gui.getKey("universal.optionMenu-alt1"),
Modifier: gocui.ModNone,
Handler: gui.handleCreateOptionsMenu,
},
{
ViewName: "",
Key: gocui.MouseMiddle,
Modifier: gocui.ModNone,
Handler: gui.handleCreateOptionsMenu,
},
{
ViewName: "status",
Key: gui.getKey("universal.edit"),
Modifier: gocui.ModNone,
Handler: gui.handleEditConfig,
Description: gui.Tr.SLocalize("EditConfig"),
},
{
ViewName: "",
Key: gui.getKey("universal.nextScreenMode"),
Modifier: gocui.ModNone,
Handler: gui.nextScreenMode,
Description: gui.Tr.SLocalize("nextScreenMode"),
},
{
ViewName: "",
Key: gui.getKey("universal.prevScreenMode"),
Modifier: gocui.ModNone,
Handler: gui.prevScreenMode,
Description: gui.Tr.SLocalize("prevScreenMode"),
},
{
ViewName: "status",
Key: gui.getKey("universal.openFile"),
Modifier: gocui.ModNone,
Handler: gui.handleOpenConfig,
Description: gui.Tr.SLocalize("OpenConfig"),
},
{
ViewName: "status",
Key: gui.getKey("status.checkForUpdate"),
Modifier: gocui.ModNone,
Handler: gui.handleCheckForUpdate,
Description: gui.Tr.SLocalize("checkForUpdate"),
},

{
ViewName: "menu",
Key: gui.getKey("universal.return"),
Modifier: gocui.ModNone,
Handler: gui.handleMenuClose,
Description: gui.Tr.SLocalize("closeMenu"),
},
{
ViewName: "menu",
Key: gui.getKey("universal.quit"),
Modifier: gocui.ModNone,
Handler: gui.handleMenuClose,
Description: gui.Tr.SLocalize("closeMenu"),
},
{
ViewName: "information",
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
Handler: gui.handleInfoClick,
},
{
ViewName: "secondary",
Contexts: []string{"normal"},
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
Handler: gui.handleMouseDownSecondary,
},
{
ViewName: "status",
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
Handler: gui.handleStatusClick,
},
{
ViewName: "search",
Key: gocui.KeyEnter,
Modifier: gocui.ModNone,
Handler: gui.handleSearch,
},
{
ViewName: "search",
Key: gui.getKey("universal.return"),
Modifier: gocui.ModNone,
Handler: gui.handleSearchEscape,
},
{
ViewName: "confirmation",
Key: gui.getKey("universal.prevItem"),
Modifier: gocui.ModNone,
Handler: gui.scrollUpConfirmationPanel,
},
{
ViewName: "confirmation",
Key: gui.getKey("universal.nextItem"),
Modifier: gocui.ModNone,
Handler: gui.scrollDownConfirmationPanel,
},
{
ViewName: "confirmation",
Key: gui.getKey("universal.prevItem-alt"),
Modifier: gocui.ModNone,
Handler: gui.scrollUpConfirmationPanel,
},
{
ViewName: "confirmation",
Key: gui.getKey("universal.nextItem-alt"),
Modifier: gocui.ModNone,
Handler: gui.scrollDownConfirmationPanel,
},
{
ViewName: "packages",
Key: gui.getKey("universal.select"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleCheckoutPackage),
},
{
ViewName: "packages",
Key: gui.getKey("packages.publish"),
Handler: gui.wrappedPackageHandler(gui.handlePublishPackage),
},
{
ViewName: "packages",
Key: gui.getKey("universal.new"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleAddPackage),
Description: "add package to list",
},
{
ViewName: "packages",
Key: gui.getKey("packages.pack"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handlePackPackage),
Description: fmt.Sprintf("%s package", utils.ColoredString("`npm pack`", color.FgYellow)),
},
{
ViewName: "packages",
Key: gui.getKey("packages.link"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleLinkPackage),
Description: fmt.Sprintf("%s (or unlink if already linked)", utils.ColoredString("`npm link <package>`", color.FgYellow)),
},
{
ViewName: "packages",
Key: gui.getKey("packages.globalLink"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleGlobalLinkPackage),
Description: fmt.Sprintf("%s (i.e. globally link) (or unlink if already linked)", utils.ColoredString("`npm link`", color.FgYellow)),
},
{
ViewName: "packages",
Key: gui.getKey("universal.remove"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleRemovePackage),
Description: "remove package from list",
},
{
ViewName: "packages",
Key: gui.getKey("universal.install"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleInstall),
Description: fmt.Sprintf("%s package", utils.ColoredString("`npm install`", color.FgYellow)),
},
{
ViewName: "packages",
Key: gui.getKey("packages.build"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleBuild),
Description: fmt.Sprintf("%s package", utils.ColoredString("`npm run build`", color.FgYellow)),
},
{
ViewName: "packages",
Key: gui.getKey("universal.openFile"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleOpenPackageConfig),
Description: "open package.json",
},
{
ViewName: "scripts",
Key: gui.getKey("universal.select"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleRunScript),
Description: fmt.Sprintf("%s script", utils.ColoredString("`npm run`", color.FgYellow)),
},
{
ViewName: "scripts",
Key: gui.getKey("universal.remove"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleRemoveScript),
Description: "remove script from package.json",
},
{
ViewName: "deps",
Key: gui.getKey("universal.install"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleDepInstall),
Description: fmt.Sprintf("%s dependency", utils.ColoredString("`npm install`", color.FgYellow)),
},
{
ViewName: "deps",
Key: gui.getKey("universal.openFile"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleOpenDepPackageConfig),
Description: "open package.json",
},
{
ViewName: "deps",
Key: gui.getKey("universal.update"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleDepUpdate),
Description: fmt.Sprintf("%s dependency", utils.ColoredString("`npm update`", color.FgYellow)),
},
{
ViewName: "deps",
Key: gui.getKey("universal.remove"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleDepUninstall),
Description: fmt.Sprintf("%s dependency", utils.ColoredString("`npm uninstall`", color.FgYellow)),
},
}

for _, viewName := range []string{"status", "packages", "deps", "scripts", "menu"} {
bindings = append(bindings, []*Binding{
{ViewName: viewName, Key: gui.getKey("universal.togglePanel"), Modifier: gocui.ModNone, Handler: gui.nextView},
{ViewName: viewName, Key: gui.getKey("universal.prevBlock"), Modifier: gocui.ModNone, Handler: gui.previousView},
{ViewName: viewName, Key: gui.getKey("universal.nextBlock"), Modifier: gocui.ModNone, Handler: gui.nextView},
{ViewName: viewName, Key: gui.getKey("universal.prevBlock-alt"), Modifier: gocui.ModNone, Handler: gui.previousView},
{ViewName: viewName, Key: gui.getKey("universal.nextBlock-alt"), Modifier: gocui.ModNone, Handler: gui.nextView},
{ViewName: viewName, Key: gui.getKey("universal.togglePanel"), Handler: gui.nextView},
{ViewName: viewName, Key: gui.getKey("universal.prevBlock"), Handler: gui.previousView},
{ViewName: viewName, Key: gui.getKey("universal.nextBlock"), Handler: gui.nextView},
{ViewName: viewName, Key: gui.getKey("universal.prevBlock-alt"), Handler: gui.previousView},
{ViewName: viewName, Key: gui.getKey("universal.nextBlock-alt"), Handler: gui.nextView},
}...)
}

// Appends keybindings to jump to a particular sideView using numbers
for i, viewName := range []string{"status", "packages", "deps", "scripts"} {
bindings = append(bindings, &Binding{ViewName: "", Key: rune(i+1) + '0', Modifier: gocui.ModNone, Handler: gui.goToSideView(viewName)})
bindings = append(bindings, &Binding{ViewName: "", Key: rune(i+1) + '0', Handler: gui.goToSideView(viewName)})
}

for _, listView := range gui.getListViews() {
bindings = append(bindings, []*Binding{
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.prevItem-alt"), Modifier: gocui.ModNone, Handler: listView.handlePrevLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.prevItem"), Modifier: gocui.ModNone, Handler: listView.handlePrevLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: listView.handlePrevLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.nextItem-alt"), Modifier: gocui.ModNone, Handler: listView.handleNextLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.nextItem"), Modifier: gocui.ModNone, Handler: listView.handleNextLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.prevPage"), Modifier: gocui.ModNone, Handler: listView.handlePrevPage, Description: gui.Tr.SLocalize("prevPage")},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.nextPage"), Modifier: gocui.ModNone, Handler: listView.handleNextPage, Description: gui.Tr.SLocalize("nextPage")},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.gotoTop"), Modifier: gocui.ModNone, Handler: listView.handleGotoTop, Description: gui.Tr.SLocalize("gotoTop")},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: listView.handleNextLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: listView.handleClick},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.prevItem-alt"), Handler: listView.handlePrevLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.prevItem"), Handler: listView.handlePrevLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gocui.MouseWheelUp, Handler: listView.handlePrevLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.nextItem-alt"), Handler: listView.handleNextLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.nextItem"), Handler: listView.handleNextLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.prevPage"), Handler: listView.handlePrevPage, Description: gui.Tr.SLocalize("prevPage")},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.nextPage"), Handler: listView.handleNextPage, Description: gui.Tr.SLocalize("nextPage")},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gui.getKey("universal.gotoTop"), Handler: listView.handleGotoTop, Description: gui.Tr.SLocalize("gotoTop")},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gocui.MouseWheelDown, Handler: listView.handleNextLine},
{ViewName: listView.viewName, Contexts: []string{listView.context}, Key: gocui.MouseLeft, Handler: listView.handleClick},
{
ViewName: listView.viewName,
Contexts: []string{listView.context},
Key: gui.getKey("universal.startSearch"),
Modifier: gocui.ModNone,
Handler: gui.handleOpenSearch,
Description: gui.Tr.SLocalize("startSearch"),
},
{
ViewName: listView.viewName,
Contexts: []string{listView.context},
Key: gui.getKey("universal.gotoBottom"),
Modifier: gocui.ModNone,
Handler: listView.handleGotoBottom,
Description: gui.Tr.SLocalize("gotoBottom"),
},
Expand Down
Loading

0 comments on commit ce9cf9d

Please sign in to comment.