summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-04-04 23:51:59 +1000
committerJesse Duffield <jessedduffield@gmail.com>2021-04-06 19:34:32 +1000
commit4fe512ff3a299102c2bd78bc83b8644582127aae (patch)
tree5a34eacc1c137a8c98624ba29b757c0a717cf694 /pkg
parent4197921465a6cb67d5fdd5b63de653493a5ebd41 (diff)
test
type safe view access
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/branches_panel.go6
-rw-r--r--pkg/gui/cherry_picking.go10
-rw-r--r--pkg/gui/commit_files_panel.go5
-rw-r--r--pkg/gui/commit_message_panel.go9
-rw-r--r--pkg/gui/commits_panel.go4
-rw-r--r--pkg/gui/confirmation_panel.go27
-rw-r--r--pkg/gui/context.go120
-rw-r--r--pkg/gui/credentials_panel.go2
-rw-r--r--pkg/gui/custom_commands.go9
-rw-r--r--pkg/gui/diffing.go4
-rw-r--r--pkg/gui/files_panel.go28
-rw-r--r--pkg/gui/global_handlers.go57
-rw-r--r--pkg/gui/gui.go28
-rw-r--r--pkg/gui/keybindings.go8
-rw-r--r--pkg/gui/layout.go311
-rw-r--r--pkg/gui/line_by_line_panel.go24
-rw-r--r--pkg/gui/list_context.go34
-rw-r--r--pkg/gui/main_panels.go36
-rw-r--r--pkg/gui/menu_panel.go1
-rw-r--r--pkg/gui/merge_panel.go9
-rw-r--r--pkg/gui/patch_building_panel.go8
-rw-r--r--pkg/gui/pty.go5
-rw-r--r--pkg/gui/recent_repos_panel.go2
-rw-r--r--pkg/gui/reflog_panel.go4
-rw-r--r--pkg/gui/remote_branches_panel.go4
-rw-r--r--pkg/gui/remotes_panel.go11
-rw-r--r--pkg/gui/searching.go2
-rw-r--r--pkg/gui/side_window.go4
-rw-r--r--pkg/gui/staging_panel.go10
-rw-r--r--pkg/gui/stash_panel.go4
-rw-r--r--pkg/gui/status_panel.go6
-rw-r--r--pkg/gui/sub_commits_panel.go8
-rw-r--r--pkg/gui/submodules_panel.go6
-rw-r--r--pkg/gui/suggestions_panel.go7
-rw-r--r--pkg/gui/tags_panel.go89
-rw-r--r--pkg/gui/view_helpers.go82
36 files changed, 480 insertions, 504 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index 4d0c69a99..6f88e3843 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -30,13 +30,13 @@ func (gui *Gui) handleBranchSelect() error {
var task updateTask
branch := gui.getSelectedBranch()
if branch == nil {
- task = gui.createRenderStringTask(gui.Tr.NoBranchesThisRepo)
+ task = NewRenderStringTask(gui.Tr.NoBranchesThisRepo)
} else {
cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.GetBranchGraphCmdStr(branch.Name),
)
- task = gui.createRunPtyTask(cmd)
+ task = NewRunPtyTask(cmd)
}
return gui.refreshMainViews(refreshMainOpts{
@@ -473,7 +473,7 @@ func (gui *Gui) currentBranch() *models.Branch {
}
func (gui *Gui) handleNewBranchOffCurrentItem() error {
- context := gui.currentSideContext()
+ context := gui.currentSideListContext()
item, ok := context.GetSelectedItem()
if !ok {
diff --git a/pkg/gui/cherry_picking.go b/pkg/gui/cherry_picking.go
index a9620896a..3ad52a73c 100644
--- a/pkg/gui/cherry_picking.go
+++ b/pkg/gui/cherry_picking.go
@@ -24,7 +24,7 @@ func (gui *Gui) handleCopyCommit() error {
}
// get currently selected commit, add the sha to state.
- context := gui.currentSideContext()
+ context := gui.currentSideListContext()
if context == nil {
return nil
}
@@ -63,7 +63,7 @@ func (gui *Gui) cherryPickedCommitShaMap() map[string]bool {
}
func (gui *Gui) commitsListForContext() []*models.Commit {
- context := gui.currentSideContext()
+ context := gui.currentSideListContext()
if context == nil {
return nil
}
@@ -104,7 +104,7 @@ func (gui *Gui) handleCopyCommitRange() error {
}
// get currently selected commit, add the sha to state.
- context := gui.currentSideContext()
+ context := gui.currentSideListContext()
if context == nil {
return nil
}
@@ -169,7 +169,7 @@ func (gui *Gui) exitCherryPickingMode() error {
return gui.rerenderContextViewIfPresent(contextKey)
}
-func (gui *Gui) rerenderContextViewIfPresent(contextKey string) error {
+func (gui *Gui) rerenderContextViewIfPresent(contextKey ContextKey) error {
if contextKey == "" {
return nil
}
@@ -184,7 +184,7 @@ func (gui *Gui) rerenderContextViewIfPresent(contextKey string) error {
return nil
}
- if view.Context == contextKey {
+ if ContextKey(view.Context) == contextKey {
if err := context.HandleRender(); err != nil {
return err
}
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go
index f0223a15e..b0bd16547 100644
--- a/pkg/gui/commit_files_panel.go
+++ b/pkg/gui/commit_files_panel.go
@@ -45,7 +45,7 @@ func (gui *Gui) handleCommitFileSelect() error {
cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.ShowFileDiffCmdStr(from, to, reverse, node.GetPath(), false),
)
- task := gui.createRunPtyTask(cmd)
+ task := NewRunPtyTask(cmd)
return gui.refreshMainViews(refreshMainOpts{
main: &viewUpdateOpts{
@@ -287,7 +287,8 @@ func (gui *Gui) handleToggleCommitFileTreeView() error {
}
}
- if gui.getCommitFilesView().Context == COMMIT_FILES_CONTEXT_KEY {
+ // TODO: pretty sure this view only ever has this context. Is this if condition necessary?
+ if gui.Views.CommitFiles.Context == COMMIT_FILES_CONTEXT_KEY {
if err := gui.State.Contexts.CommitFiles.HandleRender(); err != nil {
return err
}
diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go
index 35d3b0c80..346fbcff3 100644
--- a/pkg/gui/commit_message_panel.go
+++ b/pkg/gui/commit_message_panel.go
@@ -23,8 +23,7 @@ func (gui *Gui) runSyncOrAsyncCommand(sub *exec.Cmd, err error) (bool, error) {
}
func (gui *Gui) handleCommitConfirm() error {
- commitMessageView := gui.getCommitMessageView()
- message := gui.trimmedContent(commitMessageView)
+ message := gui.trimmedContent(gui.Views.CommitMessage)
if message == "" {
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
}
@@ -41,7 +40,7 @@ func (gui *Gui) handleCommitConfirm() error {
return nil
}
- gui.clearEditorView(commitMessageView)
+ gui.clearEditorView(gui.Views.CommitMessage)
_ = gui.returnFromContext()
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
}
@@ -73,6 +72,6 @@ func (gui *Gui) RenderCommitLength() {
if !gui.Config.GetUserConfig().Gui.CommitLength.Show {
return
}
- v := gui.getCommitMessageView()
- v.Subtitle = gui.getBufferLength(v)
+
+ gui.Views.CommitMessage.Subtitle = gui.getBufferLength(gui.Views.CommitMessage)
}
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index 4da9e1922..026316700 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -35,12 +35,12 @@ func (gui *Gui) handleCommitSelect() error {
var task updateTask
commit := gui.getSelectedLocalCommit()
if commit == nil {
- task = gui.createRenderStringTask(gui.Tr.NoCommitsThisBranch)
+ task = NewRenderStringTask(gui.Tr.NoCommitsThisBranch)
} else {
cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.GetPath()),
)
- task = gui.createRunPtyTask(cmd)
+ task = NewRunPtyTask(cmd)
}
return gui.refreshMainViews(refreshMainOpts{
diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go
index f4b62f219..737ee3ff6 100644
--- a/pkg/gui/confirmation_panel.go
+++ b/pkg/gui/confirmation_panel.go
@@ -108,19 +108,17 @@ func (gui *Gui) wrappedPromptConfirmationFunction(handlersManageFocus bool, func
}
}
-func (gui *Gui) deleteConfirmationView() {
+func (gui *Gui) clearConfirmationViewKeyBindings() {
keybindingConfig := gui.Config.GetUserConfig().Keybinding
_ = gui.g.DeleteKeybinding("confirmation", gui.getKey(keybindingConfig.Universal.Confirm), gocui.ModNone)
_ = gui.g.DeleteKeybinding("confirmation", gui.getKey(keybindingConfig.Universal.ConfirmAlt1), gocui.ModNone)
_ = gui.g.DeleteKeybinding("confirmation", gui.getKey(keybindingConfig.Universal.Return), gocui.ModNone)
-
- _ = gui.g.DeleteView("confirmation")
}
func (gui *Gui) closeConfirmationPrompt(handlersManageFocus bool) error {
- view := gui.getConfirmationView()
- if view == nil {
- return nil // if it's already been closed we can just return
+ // we've already closed it so we can just return
+ if !gui.Views.Confirmation.Visible {
+ return nil
}
if !handlersManageFocus {
@@ -129,9 +127,9 @@ func (gui *Gui) closeConfirmationPrompt(handlersManageFocus bool) error {
}
}
- gui.deleteConfirmationView()
-
- _, _ = gui.g.SetViewOnBottom("suggestions")
+ gui.clearConfirmationViewKeyBindings()
+ gui.Views.Confirmation.Visible = false
+ gui.Views.Suggestions.Visible = false
return nil
}
@@ -200,7 +198,7 @@ func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, f
suggestionsView.FgColor = theme.GocuiDefaultTextColor
}
gui.setSuggestions([]*types.Suggestion{})
- _, _ = gui.g.SetViewOnTop("suggestions")
+ suggestionsView.Visible = true
}
gui.g.Update(func(g *gocui.Gui) error {
@@ -211,10 +209,9 @@ func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, f
func (gui *Gui) createPopupPanel(opts createPopupPanelOpts) error {
gui.g.Update(func(g *gocui.Gui) error {
- // delete the existing confirmation panel if it exists
- if view, _ := g.View("confirmation"); view != nil {
- gui.deleteConfirmationView()
- }
+ // remove any previous keybindings
+ gui.clearConfirmationViewKeyBindings()
+
confirmationView, err := gui.prepareConfirmationPanel(opts.title, opts.prompt, opts.hasLoader, opts.findSuggestionsFunc)
if err != nil {
return err
@@ -251,7 +248,7 @@ func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error {
gui.renderString("options", actions)
var onConfirm func() error
if opts.handleConfirmPrompt != nil {
- onConfirm = gui.wrappedPromptConfirmationFunction(opts.handlersManageFocus, opts.handleConfirmPrompt, func() string { return gui.getConfirmationView().Buffer() })
+ onConfirm = gui.wrappedPromptConfirmationFunction(opts.handlersManageFocus, opts.handleConfirmPrompt, func() string { return gui.Views.Confirmation.Buffer() })
} else {
onConfirm = gui.wrappedConfirmationFunction(opts.handlersManageFocus, opts.handleConfirm)
}
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index 8d2d92cc9..94e227d0e 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -15,32 +15,34 @@ const (
PERSISTENT_POPUP
)
+type ContextKey string
+
const (
- STATUS_CONTEXT_KEY = "status"
- FILES_CONTEXT_KEY = "files"
- LOCAL_BRANCHES_CONTEXT_KEY = "localBranches"
- REMOTES_CONTEXT_KEY = "remotes"
- REMOTE_BRANCHES_CONTEXT_KEY = "remoteBranches"
- TAGS_CONTEXT_KEY = "tags"
- BRANCH_COMMITS_CONTEXT_KEY = "commits"
- REFLOG_COMMITS_CONTEXT_KEY = "reflogCommits"
- SUB_COMMITS_CONTEXT_KEY = "subCommits"
- COMMIT_FILES_CONTEXT_KEY = "commitFiles"
- STASH_CONTEXT_KEY = "stash"
- MAIN_NORMAL_CONTEXT_KEY = "normal"
- MAIN_MERGING_CONTEXT_KEY = "merging"
- MAIN_PATCH_BUILDING_CONTEXT_KEY = "patchBuilding"
- MAIN_STAGING_CONTEXT_KEY = "staging"
- MENU_CONTEXT_KEY = "menu"
- CREDENTIALS_CONTEXT_KEY = "credentials"
- CONFIRMATION_CONTEXT_KEY = "confirmation"
- SEARCH_CONTEXT_KEY = "search"
- COMMIT_MESSAGE_CONTEXT_KEY = "commitMessage"
- SUBMODULES_CONTEXT_KEY = "submodules"
- SUGGESTIONS_CONTEXT_KEY = "suggestions"
+ STATUS_CONTEXT_KEY ContextKey = "status"
+ FILES_CONTEXT_KEY = "files"
+ LOCAL_BRANCHES_CONTEXT_KEY = "localBranches"
+ REMOTES_CONTEXT_KEY = "remotes"
+ REMOTE_BRANCHES_CONTEXT_KEY = "remoteBranches"
+ TAGS_CONTEXT_KEY = "tags"
+ BRANCH_COMMITS_CONTEXT_KEY = "commits"
+ REFLOG_COMMITS_CONTEXT_KEY = "reflogCommits"
+ SUB_COMMITS_CONTEXT_KEY = "subCommits"
+ COMMIT_FILES_CONTEXT_KEY = "commitFiles"
+ STASH_CONTEXT_KEY = "stash"
+ MAIN_NORMAL_CONTEXT_KEY = "normal"
+ MAIN_MERGING_CONTEXT_KEY = "merging"
+ MAIN_PATCH_BUILDING_CONTEXT_KEY = "patchBuilding"
+ MAIN_STAGING_CONTEXT_KEY = "staging"
+ MENU_CONTEXT_KEY = "menu"
+ CREDENTIALS_CONTEXT_KEY = "credentials"
+ CONFIRMATION_CONTEXT_KEY = "confirmation"
+ SEARCH_CONTEXT_KEY = "search"
+ COMMIT_MESSAGE_CONTEXT_KEY = "commitMessage"
+ SUBMODULES_CONTEXT_KEY = "submodules"
+ SUGGESTIONS_CONTEXT_KEY = "suggestions"
)
-var allContextKeys = []string{
+var allContextKeys = []ContextKey{
STATUS_CONTEXT_KEY,
FILES_CONTEXT_KEY,
LOCAL_BRANCHES_CONTEXT_KEY,
@@ -124,7 +126,7 @@ type Context interface {
GetViewName() string
GetWindowName() string
SetWindowName(string)
- GetKey() string
+ GetKey() ContextKey
SetParentContext(Context)
// we return a bool here to tell us whether or not the returned value just wraps a nil
@@ -138,7 +140,7 @@ type BasicContext struct {
OnRender func() error
OnGetOptionsMap func() map[string]string
Kind ContextKind
- Key string
+ Key ContextKey
ViewName string
}
@@ -192,7 +194,7 @@ func (c BasicContext) GetKind() ContextKind {
return c.Kind
}
-func (c BasicContext) GetKey() string {
+func (c BasicContext) GetKey() ContextKey {
return c.Key
}
@@ -353,7 +355,7 @@ func (tree ContextTree) initialViewTabContextMap() map[string][]tabContext {
}
}
-func (gui *Gui) currentContextKeyIgnoringPopups() string {
+func (gui *Gui) currentContextKeyIgnoringPopups() ContextKey {
gui.State.ContextManager.Lock()
defer gui.State.ContextManager.Unlock()
@@ -461,7 +463,10 @@ func (gui *Gui) returnFromContext() error {
func (gui *Gui) deactivateContext(c Context) error {
// if we are the kind of context that is sent to back upon deactivation, we should do that
if c.GetKind() == TEMPORARY_POPUP || c.GetKind() == PERSISTENT_POPUP || c.GetKey() == COMMIT_FILES_CONTEXT_KEY {
- _, _ = gui.g.SetViewOnBottom(c.GetViewName())
+ view, err := gui.g.View(c.GetViewName())
+ if err == nil {
+ view.Visible = false
+ }
}
if err := c.HandleFocusLost(); err != nil {
@@ -480,7 +485,7 @@ func (gui *Gui) postRefreshUpdate(c Context) error {
return nil
}
- if v.Context != c.GetKey() {
+ if ContextKey(v.Context) != c.GetKey() {
return nil
}
@@ -504,7 +509,7 @@ func (gui *Gui) activateContext(c Context) error {
if err != nil {
return gui.returnFromContext()
}
- originalViewContextKey := v.Context
+ originalViewContextKey := ContextKey(v.Context)
// ensure that any other window for which this view was active is now set to the default for that window.
gui.setViewAsActiveForWindow(viewName)
@@ -522,10 +527,7 @@ func (gui *Gui) activateContext(c Context) error {
return gui.returnFromContext()
}
- if _, err := gui.g.SetViewOnTop(viewName); err != nil {
- // if view no longer exists, pop again
- return gui.returnFromContext()
- }
+ v.Visible = true
// if the new context's view was previously displaying another context, render the new context
if originalViewContextKey != c.GetKey() {
@@ -534,7 +536,7 @@ func (gui *Gui) activateContext(c Context) error {
}
}
- v.Context = c.GetKey()
+ v.Context = string(c.GetKey())
gui.g.Cursor = v.Editable
@@ -559,7 +561,7 @@ func (gui *Gui) activateContext(c Context) error {
func (gui *Gui) renderContextStack() string {
result := ""
for _, context := range gui.State.ContextManager.ContextStack {
- result += context.GetKey() + "\n"
+ result += string(context.GetKey()) + "\n"
}
return result
}
@@ -575,7 +577,18 @@ func (gui *Gui) currentContext() Context {
return gui.State.ContextManager.ContextStack[len(gui.State.ContextManager.ContextStack)-1]
}
-func (gui *Gui) currentSideContext() *ListContext {
+// the status panel is not yet a list context (and may never be), so this method is not
+// quite the same as currentSideContext()
+func (gui *Gui) currentSideListContext() *ListContext {
+ context := gui.currentSideContext()
+ listContext, ok := context.(*ListContext)
+ if !ok {
+ return nil
+ }
+ return listContext
+}
+
+func (gui *Gui) currentSideContext() Context {
gui.State.ContextManager.Lock()
defer gui.State.ContextManager.Unlock()
@@ -583,7 +596,7 @@ func (gui *Gui) currentSideContext() *ListContext {
// on startup the stack can be empty so we'll return an empty string in that case
if len(stack) == 0 {
- return nil
+ return gui.defaultSideContext()
}
// find the first context in the stack with the type of SIDE_CONTEXT
@@ -591,20 +604,19 @@ func (gui *Gui) currentSideContext() *ListContext {
context := stack[len(stack)-1-i]
if context.GetKind() == SIDE_CONTEXT {
- // not all side contexts are list contexts (e.g. the status panel)
- listContext, ok := context.(*ListContext)
- if !ok {
- return nil
- }
- return listContext
+ return context
}
}
- return nil
+ return gui.defaultSideContext()
}
func (gui *Gui) defaultSideContext() Context {
- return gui.State.Contexts.Files
+ if gui.State.Modes.Filtering.Active() {
+ return gui.State.Contexts.BranchCommits
+ } else {
+ return gui.State.Contexts.Files
+ }
}
// remove the need to do this: always use a mapping
@@ -618,7 +630,7 @@ func (gui *Gui) setInitialViewContexts() {
continue
}
- view.Context = context.GetKey()
+ view.Context = string(context.GetKey())
}
}
@@ -678,15 +690,15 @@ func (gui *Gui) onViewFocusLost(v *gocui.View, newView *gocui.View) error {
// which currently just means a context that affects both the main and secondary views
// other views can have their context changed directly but this function helps
// keep the main and secondary views in sync
-func (gui *Gui) changeMainViewsContext(contextKey string) {
+func (gui *Gui) changeMainViewsContext(contextKey ContextKey) {
if gui.State.MainContext == contextKey {
return
}
switch contextKey {
case MAIN_NORMAL_CONTEXT_KEY, MAIN_PATCH_BUILDING_CONTEXT_KEY, MAIN_STAGING_CONTEXT_KEY, MAIN_MERGING_CONTEXT_KEY:
- gui.getMainView().Context = contextKey
- gui.getSecondaryView().Context = contextKey
+ gui.Views.Main.Context = string(contextKey)
+ gui.Views.Secondary.Context = string(contextKey)
default:
panic(fmt.Sprintf("unknown context for main: %s", contextKey))
}
@@ -737,7 +749,7 @@ type tabContext struct {
contexts []Context
}
-func (gui *Gui) mustContextForContextKey(contextKey string) Context {
+func (gui *Gui) mustContextForContextKey(contextKey ContextKey) Context {
context, ok := gui.contextForContextKey(contextKey)
if !ok {
@@ -747,7 +759,7 @@ func (gui *Gui) mustContextForContextKey(contextKey string) Context {
return context
}
-func (gui *Gui) contextForContextKey(contextKey string) (Context, bool) {
+func (gui *Gui) contextForContextKey(contextKey ContextKey) (Context, bool) {
for _, context := range gui.allContexts() {
if context.GetKey() == contextKey {
return context, true
@@ -763,7 +775,7 @@ func (gui *Gui) rerenderView(viewName string) error {
return nil
}
- contextKey := v.Context
+ contextKey := ContextKey(v.Context)
context := gui.mustContextForContextKey(contextKey)
return context.HandleRender()
@@ -782,7 +794,7 @@ func (gui *Gui) rerenderView(viewName string) error {
// }
func (gui *Gui) getSideContextSelectedItemId() string {
- currentSideContext := gui.currentSideContext()
+ currentSideContext := gui.currentSideListContext()
if currentSideContext == nil {
return ""
}
diff --git a/pkg/gui/credentials_panel.go b/pkg/gui/credentials_panel.go
index 3410d3dee..107a5038c 100644
--- a/pkg/gui/credentials_panel.go
+++ b/pkg/gui/credentials_panel.go
@@ -40,7 +40,7 @@ func (gui *Gui) promptUserForCredential(passOrUname string) string {
}
func (gui *Gui) handleSubmitCredential() error {
- credentialsView := gui.getCredentialsView()
+ credentialsView := gui.Views.Credentials
message := gui.trimmedContent(credentialsView)
gui.credentials <- message
gui.clearEditorView(credentialsView)
diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go
index 09af7065c..59c08bcf1 100644
--- a/pkg/gui/custom_commands.go
+++ b/pkg/gui/custom_commands.go
@@ -176,9 +176,14 @@ func (gui *Gui) GetCustomCommandKeybindings() []*Binding {
case "":
log.Fatalf("Error parsing custom command keybindings: context not provided (use context: 'global' for the global context). Key: %s, Command: %s", customCommand.Key, customCommand.Command)
default:
- context, ok := gui.contextForContextKey(customCommand.Context)
+ context, ok := gui.contextForContextKey(ContextKey(customCommand.Context))
+ // stupid golang making me build an array of strings for this.
+ allContextKeyStrings := make([]string, len(allContextKeys))
+ for i := range allContextKeys {
+ allContextKeyStrings[i] = string(allContextKeys[i])
+ }
if !ok {
- log.Fatalf("Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s.\nPermitted contexts: %s", customCommand.Context, customCommand.Key, customCommand.Command, strings.Join(allContextKeys, ", "))
+ log.Fatalf("Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s.\nPermitted contexts: %s", customCommand.Context, customCommand.Key, customCommand.Command, strings.Join(allContextKeyStrings, ", "))
}
// here we assume that a given context will always belong to the same view.
// Currently this is a safe bet but it's by no means guaranteed in the long term
diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go
index bd29664fe..5ac83fe24 100644
--- a/pkg/gui/diffing.go
+++ b/pkg/gui/diffing.go
@@ -14,7 +14,7 @@ func (gui *Gui) renderDiff() error {
cmd := gui.OSCommand.ExecutableFromString(
fmt.Sprintf("git diff --submodule --no-ext-diff --color %s", gui.diffStr()),
)
- task := gui.createRunPtyTask(cmd)
+ task := NewRunPtyTask(cmd)
return gui.refreshMainViews(refreshMainOpts{
main: &viewUpdateOpts{
@@ -49,7 +49,7 @@ func (gui *Gui) currentDiffTerminals() []string {
}
return nil
default:
- context := gui.currentSideContext()
+ context := gui.currentSideListContext()
if context == nil {
return nil
}
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index 5d8601861..261635770 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -42,7 +42,7 @@ func (gui *Gui) getSelectedPath() string {
}
func (gui *Gui) selectFile(alreadySelected bool) error {
- gui.getFilesView().FocusPoint(0, gui.State.Panels.Files.SelectedLineIdx)
+ gui.Views.Files.FocusPoint(0, gui.State.Panels.Files.SelectedLineIdx)
node := gui.getSelectedFileNode()
@@ -50,17 +50,17 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
return gui.refreshMainViews(refreshMainOpts{
main: &viewUpdateOpts{
title: "",
- task: gui.createRenderStringTask(gui.Tr.NoChangedFiles),
+ task: NewRenderStringTask(gui.Tr.NoChangedFiles),
},
})
}
if !alreadySelected {
// TODO: pull into update task interface
- if err := gui.resetOrigin(gui.getMainView()); err != nil {
+ if err := gui.resetOrigin(gui.Views.Main); err != nil {
return err
}
- if err := gui.resetOrigin(gui.getSecondaryView()); err != nil {
+ if err := gui.resetOrigin(gui.Views.Secondary); err != nil {
return err
}
gui.takeOverMergeConflictScrolling()
@@ -75,7 +75,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
refreshOpts := refreshMainOpts{main: &viewUpdateOpts{
title: gui.Tr.UnstagedChanges,
- task: gui.createRunPtyTask(cmd),
+ task: NewRunPtyTask(cmd),
}}
if node.GetHasUnstagedChanges() {
@@ -85,7 +85,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
refreshOpts.secondary = &viewUpdateOpts{
title: gui.Tr.StagedChanges,
- task: gui.createRunPtyTask(cmd),
+ task: NewRunPtyTask(cmd),
}
}
} else {
@@ -105,11 +105,6 @@ func (gui *Gui) refreshFilesAndSubmodules() error {
selectedPath := gui.getSelectedPath()
- filesView := gui.getFilesView()
- if filesView == nil {
- // if the filesView hasn't been instantiated yet we just return
- return nil
- }
if err := gui.refreshStateSubmoduleConfigs(); err != nil {
return err
}
@@ -122,14 +117,14 @@ func (gui *Gui) refreshFilesAndSubmodules() error {
gui.Log.Error(err)
}
- if gui.getFilesView().Context == FILES_CONTEXT_KEY {
+ if gui.Views.Files.Context == FILES_CONTEXT_KEY {
// doing this a little custom (as opposed to using gui.postRefreshUpdate) because we handle selecting the file explicitly below
if err := gui.State.Contexts.Files.HandleRender(); err != nil {
return err
}
}
- if gui.currentContext().GetKey() == FILES_CONTEXT_KEY || (g.CurrentView() == gui.getMainView() && g.CurrentView().Context == MAIN_MERGING_CONTEXT_KEY) {
+ if gui.currentContext().GetKey() == FILES_CONTEXT_KEY || (g.CurrentView() == gui.Views.Main && g.CurrentView().Context == MAIN_MERGING_CONTEXT_KEY) {
newSelectedPath := gui.getSelectedPath()
alreadySelected := selectedPath != "" && newSelectedPath == selectedPath
if err := gui.selectFile(alreadySelected); err != nil {
@@ -350,7 +345,7 @@ func (gui *Gui) handleWIPCommitPress() error {
}
_ = gui.renderStringSync("commitMessage", skipHookPreifx)
- if err := gui.getCommitMessageView().SetCursor(len(skipHookPreifx), 0); err != nil {
+ if err := gui.Views.CommitMessage.SetCursor(len(skipHookPreifx), 0); err != nil {
return err
}
@@ -389,7 +384,6 @@ func (gui *Gui) handleCommitPress() error {
return gui.promptToStageAllAndRetry(gui.handleCommitPress)
}
- commitMessageView := gui.getCommitMessageView()
commitPrefixConfig := gui.commitPrefixConfigForRepo()
if commitPrefixConfig != nil {
prefixPattern := commitPrefixConfig.Pattern
@@ -400,7 +394,7 @@ func (gui *Gui) handleCommitPress() error {
}
prefix := rgx.ReplaceAllString(gui.getCheckedOutBranch().Name, prefixReplace)
gui.renderString("commitMessage", prefix