diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-07-21 16:06:38 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-07-21 16:06:38 +1000 |
commit | a47c889cbb385e93e895a257e12038a5827c45b8 (patch) | |
tree | ea05ee7849b9f6cfc9e699013b2a948ff3031566 /stash_panel.go | |
parent | bcdfe242ac4050c4be22fc43791f3b98952b2f73 (diff) | |
parent | 61dcbb456d42fefc8aaac456e02c40bdef7de774 (diff) |
merge with develop
Diffstat (limited to 'stash_panel.go')
-rw-r--r-- | stash_panel.go | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/stash_panel.go b/stash_panel.go index beec8648c..2f80b0f0b 100644 --- a/stash_panel.go +++ b/stash_panel.go @@ -1,65 +1,65 @@ package main import ( - "fmt" + "fmt" - "github.com/jesseduffield/gocui" + "github.com/jesseduffield/gocui" ) func refreshStashEntries(g *gocui.Gui) error { - g.Update(func(g *gocui.Gui) error { - v, err := g.View("stash") - if err != nil { - panic(err) - } - state.StashEntries = getGitStashEntries() - v.Clear() - for _, stashEntry := range state.StashEntries { - fmt.Fprintln(v, stashEntry.DisplayString) - } - return resetOrigin(v) - }) - return nil + g.Update(func(g *gocui.Gui) error { + v, err := g.View("stash") + if err != nil { + panic(err) + } + state.StashEntries = getGitStashEntries() + v.Clear() + for _, stashEntry := range state.StashEntries { + fmt.Fprintln(v, stashEntry.DisplayString) + } + return resetOrigin(v) + }) + return nil } func getSelectedStashEntry(v *gocui.View) *StashEntry { - if len(state.StashEntries) == 0 { - return nil - } - lineNumber := getItemPosition(v) - return &state.StashEntries[lineNumber] + if len(state.StashEntries) == 0 { + return nil + } + lineNumber := getItemPosition(v) + return &state.StashEntries[lineNumber] } func renderStashOptions(g *gocui.Gui) error { - return renderOptionsMap(g, map[string]string{ - "space": "apply", - "k": "pop", - "d": "drop", - }) + return renderOptionsMap(g, map[string]string{ + "space": "apply", + "k": "pop", + "d": "drop", + }) } func handleStashEntrySelect(g *gocui.Gui, v *gocui.View) error { - if err := renderStashOptions(g); err != nil { - return err - } - go func() { - stashEntry := getSelectedStashEntry(v) - if stashEntry == nil { - renderString(g, "main", "No stash entries") - return - } - diff, _ := getStashEntryDiff(stashEntry.Index) - renderString(g, "main", diff) - }() - return nil + if err := renderStashOptions(g); err != nil { + return err + } + go func() { + stashEntry := getSelectedStashEntry(v) + if stashEntry == nil { + renderString(g, "main", "No stash entries") + return + } + diff, _ := getStashEntryDiff(stashEntry.Index) + renderString(g, "main", diff) + }() + return nil } func handleStashApply(g *gocui.Gui, v *gocui.View) error { - return stashDo(g, v, "apply") + return stashDo(g, v, "apply") } func handleStashPop(g *gocui.Gui, v *gocui.View) error { - return stashDo(g, v, "pop") + return stashDo(g, v, "pop") } func handleStashDrop(g *gocui.Gui, v *gocui.View) error { @@ -70,24 +70,24 @@ func handleStashDrop(g *gocui.Gui, v *gocui.View) error { } func stashDo(g *gocui.Gui, v *gocui.View, method string) error { - stashEntry := getSelectedStashEntry(v) - if stashEntry == nil { - return createErrorPanel(g, "No stash to "+method) - } - if output, err := gitStashDo(stashEntry.Index, method); err != nil { - createErrorPanel(g, output) - } - refreshStashEntries(g) - return refreshFiles(g) + stashEntry := getSelectedStashEntry(v) + if stashEntry == nil { + return createErrorPanel(g, "No stash to "+method) + } + if output, err := gitStashDo(stashEntry.Index, method); err != nil { + createErrorPanel(g, output) + } + refreshStashEntries(g) + return refreshFiles(g) } func handleStashSave(g *gocui.Gui, filesView *gocui.View) error { - createPromptPanel(g, filesView, "Stash changes", func(g *gocui.Gui, v *gocui.View) error { - if output, err := gitStashSave(trimmedContent(v)); err != nil { - createErrorPanel(g, output) - } - refreshStashEntries(g) - return refreshFiles(g) - }) - return nil + createPromptPanel(g, filesView, "Stash changes", func(g *gocui.Gui, v *gocui.View) error { + if output, err := gitStashSave(trimmedContent(v)); err != nil { + createErrorPanel(g, output) + } + refreshStashEntries(g) + return refreshFiles(g) + }) + return nil } |