2018-08-12 11:31:27 +02:00
|
|
|
package gui
|
2018-08-08 11:18:41 +02:00
|
|
|
|
2018-09-17 13:02:30 +02:00
|
|
|
import (
|
|
|
|
"github.com/jesseduffield/gocui"
|
|
|
|
)
|
2018-08-08 11:18:41 +02:00
|
|
|
|
|
|
|
// Binding - a keybinding mapping a key and modifier to a handler. The keypress
|
|
|
|
// is only handled if the given view has focus, or handled globally if the view
|
|
|
|
// is ""
|
|
|
|
type Binding struct {
|
2018-08-29 11:56:28 +02:00
|
|
|
ViewName string
|
|
|
|
Handler func(*gocui.Gui, *gocui.View) error
|
|
|
|
Key interface{} // FIXME: find out how to get `gocui.Key | rune`
|
|
|
|
Modifier gocui.Modifier
|
2018-08-28 20:13:01 +02:00
|
|
|
Description string
|
2019-05-03 07:03:25 +02:00
|
|
|
Alternative string
|
2018-08-08 11:18:41 +02:00
|
|
|
}
|
|
|
|
|
2018-09-17 13:02:30 +02:00
|
|
|
// GetDisplayStrings returns the display string of a file
|
2019-02-16 06:17:44 +02:00
|
|
|
func (b *Binding) GetDisplayStrings(isFocused bool) []string {
|
2018-09-17 13:02:30 +02:00
|
|
|
return []string{b.GetKey(), b.Description}
|
|
|
|
}
|
|
|
|
|
2018-11-30 02:47:14 +02:00
|
|
|
// GetKey is a function.
|
2018-09-17 13:02:30 +02:00
|
|
|
func (b *Binding) GetKey() string {
|
2019-01-16 19:42:54 +02:00
|
|
|
key := 0
|
2018-09-17 13:02:30 +02:00
|
|
|
|
2019-01-16 19:42:54 +02:00
|
|
|
switch b.Key.(type) {
|
|
|
|
case rune:
|
|
|
|
key = int(b.Key.(rune))
|
|
|
|
case gocui.Key:
|
|
|
|
key = int(b.Key.(gocui.Key))
|
2018-09-17 13:02:30 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 19:42:54 +02:00
|
|
|
// special keys
|
|
|
|
switch key {
|
|
|
|
case 27:
|
|
|
|
return "esc"
|
|
|
|
case 13:
|
|
|
|
return "enter"
|
|
|
|
case 32:
|
|
|
|
return "space"
|
2019-03-02 06:11:53 +02:00
|
|
|
case 65514:
|
|
|
|
return "►"
|
|
|
|
case 65515:
|
|
|
|
return "◄"
|
|
|
|
case 65517:
|
|
|
|
return "▲"
|
|
|
|
case 65516:
|
|
|
|
return "▼"
|
|
|
|
case 65508:
|
|
|
|
return "PgUp"
|
|
|
|
case 65507:
|
|
|
|
return "PgDn"
|
2019-01-16 19:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return string(key)
|
2018-09-17 13:02:30 +02:00
|
|
|
}
|
|
|
|
|
2019-02-16 03:07:27 +02:00
|
|
|
// GetInitialKeybindings is a function.
|
|
|
|
func (gui *Gui) GetInitialKeybindings() []*Binding {
|
2018-09-17 13:02:30 +02:00
|
|
|
bindings := []*Binding{
|
2018-09-01 12:10:03 +02:00
|
|
|
{
|
|
|
|
ViewName: "",
|
|
|
|
Key: 'q',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.quit,
|
|
|
|
}, {
|
|
|
|
ViewName: "",
|
|
|
|
Key: gocui.KeyCtrlC,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.quit,
|
|
|
|
}, {
|
|
|
|
ViewName: "",
|
|
|
|
Key: gocui.KeyEsc,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.quit,
|
|
|
|
}, {
|
2019-05-03 07:03:25 +02:00
|
|
|
ViewName: "",
|
|
|
|
Key: gocui.KeyPgup,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.scrollUpMain,
|
|
|
|
Alternative: "fn+up",
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2019-05-03 07:03:25 +02:00
|
|
|
ViewName: "",
|
|
|
|
Key: gocui.KeyPgdn,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.scrollDownMain,
|
|
|
|
Alternative: "fn+down",
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "",
|
|
|
|
Key: gocui.KeyCtrlU,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.scrollUpMain,
|
|
|
|
}, {
|
|
|
|
ViewName: "",
|
|
|
|
Key: gocui.KeyCtrlD,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.scrollDownMain,
|
2019-02-19 14:36:29 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "",
|
|
|
|
Key: 'm',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCreateRebaseOptionsMenu,
|
|
|
|
Description: gui.Tr.SLocalize("ViewMergeRebaseOptions"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-05 13:23:06 +02:00
|
|
|
ViewName: "",
|
|
|
|
Key: 'P',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.pushFiles,
|
2018-09-05 13:01:21 +02:00
|
|
|
Description: gui.Tr.SLocalize("push"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-05 13:23:06 +02:00
|
|
|
ViewName: "",
|
|
|
|
Key: 'p',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.pullFiles,
|
2018-09-05 13:01:21 +02:00
|
|
|
Description: gui.Tr.SLocalize("pull"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-05 13:23:06 +02:00
|
|
|
ViewName: "",
|
|
|
|
Key: 'R',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleRefresh,
|
2018-09-05 13:01:21 +02:00
|
|
|
Description: gui.Tr.SLocalize("refresh"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "",
|
2018-09-05 15:55:24 +02:00
|
|
|
Key: 'x',
|
2018-09-01 12:10:03 +02:00
|
|
|
Modifier: gocui.ModNone,
|
2018-09-18 13:07:25 +02:00
|
|
|
Handler: gui.handleCreateOptionsMenu,
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "status",
|
|
|
|
Key: 'e',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleEditConfig,
|
|
|
|
Description: gui.Tr.SLocalize("EditConfig"),
|
|
|
|
}, {
|
|
|
|
ViewName: "status",
|
|
|
|
Key: 'o',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleOpenConfig,
|
|
|
|
Description: gui.Tr.SLocalize("OpenConfig"),
|
|
|
|
}, {
|
|
|
|
ViewName: "status",
|
|
|
|
Key: 'u',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCheckForUpdate,
|
2018-09-03 18:16:54 +02:00
|
|
|
Description: gui.Tr.SLocalize("checkForUpdate"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-19 10:40:41 +02:00
|
|
|
ViewName: "status",
|
|
|
|
Key: 's',
|
|
|
|
Modifier: gocui.ModNone,
|
2018-09-19 11:15:29 +02:00
|
|
|
Handler: gui.handleCreateRecentReposMenu,
|
2018-09-19 10:40:41 +02:00
|
|
|
Description: gui.Tr.SLocalize("SwitchRepo"),
|
|
|
|
},
|
|
|
|
{
|
2018-09-01 12:10:03 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: 'c',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitPress,
|
|
|
|
Description: gui.Tr.SLocalize("CommitChanges"),
|
2019-04-13 05:56:31 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ViewName: "files",
|
|
|
|
Key: 'w',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleWIPCommitPress,
|
|
|
|
Description: gui.Tr.SLocalize("commitChangesWithoutHook"),
|
2018-09-12 15:20:35 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "files",
|
2018-10-08 21:19:45 +02:00
|
|
|
Key: 'A',
|
2018-09-12 15:20:35 +02:00
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleAmendCommitPress,
|
2018-09-25 22:11:51 +02:00
|
|
|
Description: gui.Tr.SLocalize("AmendLastCommit"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "files",
|
|
|
|
Key: 'C',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitEditorPress,
|
|
|
|
Description: gui.Tr.SLocalize("CommitChangesWithEditor"),
|
|
|
|
}, {
|
2018-09-03 18:44:56 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: gocui.KeySpace,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleFilePress,
|
|
|
|
Description: gui.Tr.SLocalize("toggleStaged"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:03:43 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: 'd',
|
|
|
|
Modifier: gocui.ModNone,
|
2019-03-18 11:44:33 +02:00
|
|
|
Handler: gui.handleCreateDiscardMenu,
|
|
|
|
Description: gui.Tr.SLocalize("viewDiscardOptions"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: 'e',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleFileEdit,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("editFile"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: 'o',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleFileOpen,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("openFile"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: 'i',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleIgnoreFile,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("ignoreFile"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: 'r',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleRefreshFiles,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("refreshFiles"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "files",
|
2019-03-02 06:12:52 +02:00
|
|
|
Key: 'S',
|
2018-09-01 14:20:45 +02:00
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStashSave,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("stashFiles"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: 'a',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStageAll,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("toggleStagedAll"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: 't',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleAddPatch,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("addPatch"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: 'D',
|
|
|
|
Modifier: gocui.ModNone,
|
2019-03-18 12:40:32 +02:00
|
|
|
Handler: gui.handleCreateResetMenu,
|
|
|
|
Description: gui.Tr.SLocalize("viewResetOptions"),
|
2018-12-02 10:57:01 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "files",
|
|
|
|
Key: gocui.KeyEnter,
|
|
|
|
Modifier: gocui.ModNone,
|
2018-12-05 13:30:10 +02:00
|
|
|
Handler: gui.handleEnterFile,
|
2018-12-02 10:57:01 +02:00
|
|
|
Description: gui.Tr.SLocalize("StageLines"),
|
2018-12-12 13:33:42 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "files",
|
|
|
|
Key: 'f',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleGitFetch,
|
|
|
|
Description: gui.Tr.SLocalize("fetch"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2019-03-12 12:43:56 +02:00
|
|
|
ViewName: "files",
|
|
|
|
Key: 'X',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCustomCommand,
|
|
|
|
Description: gui.Tr.SLocalize("executeCustomCommand"),
|
|
|
|
}, {
|
2018-09-03 18:44:56 +02:00
|
|
|
ViewName: "branches",
|
|
|
|
Key: gocui.KeySpace,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleBranchPress,
|
|
|
|
Description: gui.Tr.SLocalize("checkout"),
|
2018-10-12 14:06:03 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "branches",
|
|
|
|
Key: 'o',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCreatePullRequestPress,
|
|
|
|
Description: gui.Tr.SLocalize("createPullRequest"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "branches",
|
|
|
|
Key: 'c',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCheckoutByName,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("checkoutByName"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "branches",
|
|
|
|
Key: 'F',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleForceCheckout,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("forceCheckout"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "branches",
|
|
|
|
Key: 'n',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleNewBranch,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("newBranch"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "branches",
|
|
|
|
Key: 'd',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleDeleteBranch,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("deleteBranch"),
|
2018-11-29 18:57:51 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "branches",
|
|
|
|
Key: 'r',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleRebase,
|
|
|
|
Description: gui.Tr.SLocalize("rebaseBranch"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "branches",
|
2019-02-19 14:36:29 +02:00
|
|
|
Key: 'M',
|
2018-09-01 14:20:45 +02:00
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleMerge,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("mergeIntoCurrentBranch"),
|
2018-12-07 09:52:31 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "branches",
|
|
|
|
Key: 'f',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleFastForward,
|
|
|
|
Description: gui.Tr.SLocalize("FastForward"),
|
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "commits",
|
|
|
|
Key: 's',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitSquashDown,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("squashDown"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'r',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleRenameCommit,
|
2018-09-03 18:16:54 +02:00
|
|
|
Description: gui.Tr.SLocalize("renameCommit"),
|
2018-09-03 18:01:07 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'R',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleRenameCommitEditor,
|
2018-09-03 18:16:54 +02:00
|
|
|
Description: gui.Tr.SLocalize("renameCommitEditor"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'g',
|
|
|
|
Modifier: gocui.ModNone,
|
2019-04-02 10:53:16 +02:00
|
|
|
Handler: gui.handleCreateCommitResetMenu,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("resetToThisCommit"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'f',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitFixup,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("fixupCommit"),
|
2019-04-07 03:35:34 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'F',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCreateFixupCommit,
|
|
|
|
Description: gui.Tr.SLocalize("createFixupCommit"),
|
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'S',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSquashAllAboveFixupCommits,
|
|
|
|
Description: gui.Tr.SLocalize("squashAboveCommits"),
|
2019-02-18 14:27:54 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'd',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitDelete,
|
|
|
|
Description: gui.Tr.SLocalize("deleteCommit"),
|
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'J',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitMoveDown,
|
|
|
|
Description: gui.Tr.SLocalize("moveDownCommit"),
|
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'K',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitMoveUp,
|
|
|
|
Description: gui.Tr.SLocalize("moveUpCommit"),
|
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'e',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitEdit,
|
|
|
|
Description: gui.Tr.SLocalize("editCommit"),
|
2019-02-19 14:36:29 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'A',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitAmendTo,
|
|
|
|
Description: gui.Tr.SLocalize("amendToCommit"),
|
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'p',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitPick,
|
|
|
|
Description: gui.Tr.SLocalize("pickCommit"),
|
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 't',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitRevert,
|
|
|
|
Description: gui.Tr.SLocalize("revertCommit"),
|
2019-02-24 04:51:52 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'c',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCopyCommit,
|
|
|
|
Description: gui.Tr.SLocalize("cherryPickCopy"),
|
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'C',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCopyCommitRange,
|
|
|
|
Description: gui.Tr.SLocalize("cherryPickCopyRange"),
|
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: 'v',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.HandlePasteCommits,
|
|
|
|
Description: gui.Tr.SLocalize("pasteCommits"),
|
2019-03-09 16:42:10 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: gocui.KeyEnter,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSwitchToCommitFilesPanel,
|
2019-03-11 00:28:47 +02:00
|
|
|
Description: gui.Tr.SLocalize("viewCommitFiles"),
|
2019-03-23 15:46:08 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "commits",
|
|
|
|
Key: gocui.KeySpace,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleToggleDiffCommit,
|
|
|
|
Description: gui.Tr.SLocalize("CommitsDiff"),
|
2018-12-07 09:52:31 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "stash",
|
|
|
|
Key: gocui.KeySpace,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStashApply,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("apply"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "stash",
|
|
|
|
Key: 'g',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStashPop,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("pop"),
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-01 14:20:45 +02:00
|
|
|
ViewName: "stash",
|
|
|
|
Key: 'd',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStashDrop,
|
2018-09-01 14:03:43 +02:00
|
|
|
Description: gui.Tr.SLocalize("drop"),
|
2018-12-07 09:52:31 +02:00
|
|
|
}, {
|
2018-09-01 12:10:03 +02:00
|
|
|
ViewName: "commitMessage",
|
|
|
|
Key: gocui.KeyEnter,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitConfirm,
|
|
|
|
}, {
|
|
|
|
ViewName: "commitMessage",
|
|
|
|
Key: gocui.KeyEsc,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCommitClose,
|
2018-10-20 17:37:55 +02:00
|
|
|
}, {
|
2018-12-10 08:51:06 +02:00
|
|
|
ViewName: "credentials",
|
2018-10-20 17:37:55 +02:00
|
|
|
Key: gocui.KeyEnter,
|
|
|
|
Modifier: gocui.ModNone,
|
2018-12-18 13:19:32 +02:00
|
|
|
Handler: gui.handleSubmitCredential,
|
2018-10-20 17:37:55 +02:00
|
|
|
}, {
|
2018-12-10 08:51:06 +02:00
|
|
|
ViewName: "credentials",
|
2018-10-20 17:37:55 +02:00
|
|
|
Key: gocui.KeyEsc,
|
|
|
|
Modifier: gocui.ModNone,
|
2018-12-18 13:19:32 +02:00
|
|
|
Handler: gui.handleCloseCredentialsView,
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-05 11:12:11 +02:00
|
|
|
ViewName: "menu",
|
2018-09-01 12:10:03 +02:00
|
|
|
Key: gocui.KeyEsc,
|
|
|
|
Modifier: gocui.ModNone,
|
2018-09-05 11:12:11 +02:00
|
|
|
Handler: gui.handleMenuClose,
|
2018-09-01 12:10:03 +02:00
|
|
|
}, {
|
2018-09-05 11:12:11 +02:00
|
|
|
ViewName: "menu",
|
2018-09-01 12:10:03 +02:00
|
|
|
Key: 'q',
|
|
|
|
Modifier: gocui.ModNone,
|
2018-09-05 11:12:11 +02:00
|
|
|
Handler: gui.handleMenuClose,
|
2019-02-25 13:11:35 +02:00
|
|
|
}, {
|
2019-03-03 05:28:16 +02:00
|
|
|
ViewName: "information",
|
2019-02-25 13:11:35 +02:00
|
|
|
Key: gocui.MouseLeft,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleDonate,
|
2019-03-09 16:42:10 +02:00
|
|
|
}, {
|
2019-03-11 00:28:47 +02:00
|
|
|
ViewName: "commitFiles",
|
2019-03-09 16:42:10 +02:00
|
|
|
Key: gocui.KeyEsc,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSwitchToCommitsPanel,
|
2019-03-11 00:28:47 +02:00
|
|
|
Description: gui.Tr.SLocalize("goBack"),
|
2019-03-11 00:53:46 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "commitFiles",
|
|
|
|
Key: 'c',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleCheckoutCommitFile,
|
|
|
|
Description: gui.Tr.SLocalize("checkoutCommitFile"),
|
2019-03-11 04:04:08 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "commitFiles",
|
|
|
|
Key: 'd',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleDiscardOldFileChange,
|
|
|
|
Description: gui.Tr.SLocalize("discardOldFileChange"),
|
2018-09-01 12:10:03 +02:00
|
|
|
},
|
2019-03-15 04:29:27 +02:00
|
|
|
{
|
|
|
|
ViewName: "commitFiles",
|
|
|
|
Key: 'o',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleOpenOldCommitFile,
|
|
|
|
Description: gui.Tr.SLocalize("openFile"),
|
|
|
|
},
|
2018-08-08 11:18:41 +02:00
|
|
|
}
|
2018-08-09 15:26:31 +02:00
|
|
|
|
2019-03-11 04:04:08 +02:00
|
|
|
for _, viewName := range []string{"status", "branches", "files", "commits", "commitFiles", "stash", "menu"} {
|
2018-09-17 13:02:30 +02:00
|
|
|
bindings = append(bindings, []*Binding{
|
2018-08-13 13:16:21 +02:00
|
|
|
{ViewName: viewName, Key: gocui.KeyTab, Modifier: gocui.ModNone, Handler: gui.nextView},
|
|
|
|
{ViewName: viewName, Key: gocui.KeyArrowLeft, Modifier: gocui.ModNone, Handler: gui.previousView},
|
|
|
|
{ViewName: viewName, Key: gocui.KeyArrowRight, Modifier: gocui.ModNone, Handler: gui.nextView},
|
|
|
|
{ViewName: viewName, Key: 'h', Modifier: gocui.ModNone, Handler: gui.previousView},
|
|
|
|
{ViewName: viewName, Key: 'l', Modifier: gocui.ModNone, Handler: gui.nextView},
|
2018-08-09 15:26:31 +02:00
|
|
|
}...)
|
|
|
|
}
|
|
|
|
|
2018-12-07 09:52:31 +02:00
|
|
|
listPanelMap := map[string]struct {
|
|
|
|
prevLine func(*gocui.Gui, *gocui.View) error
|
|
|
|
nextLine func(*gocui.Gui, *gocui.View) error
|
2019-02-25 13:11:35 +02:00
|
|
|
focus func(*gocui.Gui, *gocui.View) error
|
2018-12-07 09:52:31 +02:00
|
|
|
}{
|
2019-03-11 00:53:46 +02:00
|
|
|
"menu": {prevLine: gui.handleMenuPrevLine, nextLine: gui.handleMenuNextLine, focus: gui.handleMenuSelect},
|
|
|
|
"files": {prevLine: gui.handleFilesPrevLine, nextLine: gui.handleFilesNextLine, focus: gui.handleFilesFocus},
|
|
|
|
"branches": {prevLine: gui.handleBranchesPrevLine, nextLine: gui.handleBranchesNextLine, focus: gui.handleBranchSelect},
|
|
|
|
"commits": {prevLine: gui.handleCommitsPrevLine, nextLine: gui.handleCommitsNextLine, focus: gui.handleCommitSelect},
|
|
|
|
"stash": {prevLine: gui.handleStashPrevLine, nextLine: gui.handleStashNextLine, focus: gui.handleStashEntrySelect},
|
|
|
|
"status": {focus: gui.handleStatusSelect},
|
2019-03-11 00:28:47 +02:00
|
|
|
"commitFiles": {prevLine: gui.handleCommitFilesPrevLine, nextLine: gui.handleCommitFilesNextLine, focus: gui.handleCommitFileSelect},
|
2018-12-07 09:52:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for viewName, functions := range listPanelMap {
|
|
|
|
bindings = append(bindings, []*Binding{
|
|
|
|
{ViewName: viewName, Key: 'k', Modifier: gocui.ModNone, Handler: functions.prevLine},
|
|
|
|
{ViewName: viewName, Key: gocui.KeyArrowUp, Modifier: gocui.ModNone, Handler: functions.prevLine},
|
2019-02-25 13:11:35 +02:00
|
|
|
{ViewName: viewName, Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: functions.prevLine},
|
2018-12-07 09:52:31 +02:00
|
|
|
{ViewName: viewName, Key: 'j', Modifier: gocui.ModNone, Handler: functions.nextLine},
|
|
|
|
{ViewName: viewName, Key: gocui.KeyArrowDown, Modifier: gocui.ModNone, Handler: functions.nextLine},
|
2019-02-25 13:11:35 +02:00
|
|
|
{ViewName: viewName, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: functions.nextLine},
|
|
|
|
{ViewName: viewName, Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: functions.focus},
|
2018-12-07 09:52:31 +02:00
|
|
|
}...)
|
|
|
|
}
|
|
|
|
|
2018-08-28 20:07:13 +02:00
|
|
|
return bindings
|
|
|
|
}
|
|
|
|
|
2019-03-02 06:11:53 +02:00
|
|
|
// GetCurrentKeybindings gets the list of keybindings given the current context
|
2019-02-16 03:07:27 +02:00
|
|
|
func (gui *Gui) GetCurrentKeybindings() []*Binding {
|
|
|
|
bindings := gui.GetInitialKeybindings()
|
2019-02-25 13:11:35 +02:00
|
|
|
viewName := gui.currentViewName()
|
2019-02-16 03:07:27 +02:00
|
|
|
currentContext := gui.State.Contexts[viewName]
|
2019-03-02 06:11:53 +02:00
|
|
|
contextBindings := gui.GetContextMap()[viewName][currentContext]
|
2019-02-16 03:07:27 +02:00
|
|
|
|
|
|
|
return append(bindings, contextBindings...)
|
|
|
|
}
|
|
|
|
|
2018-08-28 20:07:13 +02:00
|
|
|
func (gui *Gui) keybindings(g *gocui.Gui) error {
|
2019-02-16 03:07:27 +02:00
|
|
|
bindings := gui.GetInitialKeybindings()
|
2018-08-28 20:07:13 +02:00
|
|
|
|
2018-08-08 11:18:41 +02:00
|
|
|
for _, binding := range bindings {
|
|
|
|
if err := g.SetKeybinding(binding.ViewName, binding.Key, binding.Modifier, binding.Handler); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2019-02-16 03:07:27 +02:00
|
|
|
if err := gui.setInitialContexts(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-03-02 06:11:53 +02:00
|
|
|
func (gui *Gui) GetContextMap() map[string]map[string][]*Binding {
|
2019-02-16 03:07:27 +02:00
|
|
|
return map[string]map[string][]*Binding{
|
|
|
|
"main": {
|
2019-03-02 06:11:53 +02:00
|
|
|
"normal": {
|
|
|
|
{
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.MouseWheelDown,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.scrollDownMain,
|
|
|
|
Description: gui.Tr.SLocalize("ScrollDown"),
|
2019-05-07 08:55:30 +02:00
|
|
|
Alternative: "fn+up",
|
2019-03-02 06:11:53 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.MouseWheelUp,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.scrollUpMain,
|
|
|
|
Description: gui.Tr.SLocalize("ScrollUp"),
|
2019-05-07 08:55:30 +02:00
|
|
|
Alternative: "fn+down",
|
2019-03-02 06:11:53 +02:00
|
|
|
},
|
|
|
|
},
|
2019-02-16 03:07:27 +02:00
|
|
|
"staging": {
|
|
|
|
{
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeyEsc,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStagingEscape,
|
|
|
|
Description: gui.Tr.SLocalize("EscapeStaging"),
|
|
|
|
}, {
|
2019-03-02 06:11:53 +02:00
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeyArrowUp,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStagingPrevLine,
|
|
|
|
Description: gui.Tr.SLocalize("PrevLine"),
|
2019-02-16 03:07:27 +02:00
|
|
|
}, {
|
2019-03-02 06:11:53 +02:00
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeyArrowDown,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStagingNextLine,
|
|
|
|
Description: gui.Tr.SLocalize("NextLine"),
|
2019-02-16 03:07:27 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'k',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStagingPrevLine,
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'j',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStagingNextLine,
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
2019-03-02 06:11:53 +02:00
|
|
|
Key: gocui.MouseWheelUp,
|
2019-02-16 03:07:27 +02:00
|
|
|
Modifier: gocui.ModNone,
|
2019-03-02 06:11:53 +02:00
|
|
|
Handler: gui.handleStagingPrevLine,
|
2019-02-16 03:07:27 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
2019-03-02 06:11:53 +02:00
|
|
|
Key: gocui.MouseWheelDown,
|
2019-02-16 03:07:27 +02:00
|
|
|
Modifier: gocui.ModNone,
|
2019-03-02 06:11:53 +02:00
|
|
|
Handler: gui.handleStagingNextLine,
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeyArrowLeft,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStagingPrevHunk,
|
|
|
|
Description: gui.Tr.SLocalize("PrevHunk"),
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeyArrowRight,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStagingNextHunk,
|
|
|
|
Description: gui.Tr.SLocalize("NextHunk"),
|
2019-02-16 03:07:27 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'h',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStagingPrevHunk,
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'l',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStagingNextHunk,
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeySpace,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStageLine,
|
|
|
|
Description: gui.Tr.SLocalize("StageLine"),
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'a',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleStageHunk,
|
|
|
|
Description: gui.Tr.SLocalize("StageHunk"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"merging": {
|
|
|
|
{
|
2019-03-02 06:11:53 +02:00
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeyEsc,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleEscapeMerge,
|
|
|
|
Description: gui.Tr.SLocalize("EscapeStaging"),
|
2019-02-16 03:07:27 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeySpace,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handlePickHunk,
|
|
|
|
Description: gui.Tr.SLocalize("PickHunk"),
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'b',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handlePickBothHunks,
|
|
|
|
Description: gui.Tr.SLocalize("PickBothHunks"),
|
|
|
|
}, {
|
2019-03-02 06:11:53 +02:00
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeyArrowLeft,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSelectPrevConflict,
|
|
|
|
Description: gui.Tr.SLocalize("PrevConflict"),
|
2019-02-16 03:07:27 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeyArrowRight,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSelectNextConflict,
|
2019-03-02 06:11:53 +02:00
|
|
|
|
|
|
|
Description: gui.Tr.SLocalize("NextConflict"),
|
2019-02-16 03:07:27 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeyArrowUp,
|
2019-03-02 06:11:53 +02:00
|
|
|
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSelectTop,
|
|
|
|
Description: gui.Tr.SLocalize("SelectTop"),
|
2019-02-16 03:07:27 +02:00
|
|
|
}, {
|
2019-03-02 06:11:53 +02:00
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.KeyArrowDown,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSelectBottom,
|
|
|
|
Description: gui.Tr.SLocalize("SelectBottom"),
|
2019-02-25 13:11:35 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.MouseWheelUp,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSelectTop,
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: gocui.MouseWheelDown,
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSelectBottom,
|
2019-02-16 03:07:27 +02:00
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'h',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSelectPrevConflict,
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'l',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSelectNextConflict,
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'k',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSelectTop,
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'j',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handleSelectBottom,
|
|
|
|
}, {
|
|
|
|
ViewName: "main",
|
|
|
|
Key: 'z',
|
|
|
|
Modifier: gocui.ModNone,
|
|
|
|
Handler: gui.handlePopFileSnapshot,
|
|
|
|
Description: gui.Tr.SLocalize("Undo"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|