diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-10 16:20:35 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-10 22:32:13 +1100 |
commit | e85310c0a92a89167530241bdc3fc5f66a48706d (patch) | |
tree | f7989a8b002d2d5aa847460cae112aac9f64b669 /pkg/gui/status_panel.go | |
parent | cd17b46b55e312b3ba4e3ab9d3d96a8eeb20fded (diff) |
add mouse support
Diffstat (limited to 'pkg/gui/status_panel.go')
-rw-r--r-- | pkg/gui/status_panel.go | 62 |
1 files changed, 51 insertions, 11 deletions
diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go index ff558f82d..6ad1c9d56 100644 --- a/pkg/gui/status_panel.go +++ b/pkg/gui/status_panel.go @@ -10,6 +10,8 @@ import ( ) func (gui *Gui) refreshStatus(g *gocui.Gui) error { + state := gui.State.Panels.Status + v, err := g.View("status") if err != nil { panic(err) @@ -19,34 +21,69 @@ func (gui *Gui) refreshStatus(g *gocui.Gui) error { // contents end up cleared g.Update(func(*gocui.Gui) error { v.Clear() - pushables, pullables := gui.GitCommand.GetCurrentBranchUpstreamDifferenceCount() - fmt.Fprint(v, "↑"+pushables+"↓"+pullables) - branches := gui.State.Branches + state.pushables, state.pullables = gui.GitCommand.GetCurrentBranchUpstreamDifferenceCount() if err := gui.updateWorkTreeState(); err != nil { return err } + status := fmt.Sprintf("↑%s↓%s", state.pushables, state.pullables) + branches := gui.State.Branches + if gui.State.WorkingTreeState != "normal" { - fmt.Fprint(v, utils.ColoredString(fmt.Sprintf(" (%s)", gui.State.WorkingTreeState), color.FgYellow)) + status += utils.ColoredString(fmt.Sprintf(" (%s)", gui.State.WorkingTreeState), color.FgYellow) } - if len(branches) == 0 { - return nil + if len(branches) > 0 { + branch := branches[0] + name := utils.ColoredString(branch.Name, branch.GetColor()) + repoName := utils.GetCurrentRepoName() + status += fmt.Sprintf(" %s → %s", repoName, name) } - branch := branches[0] - name := utils.ColoredString(branch.Name, branch.GetColor()) - repo := utils.GetCurrentRepoName() - fmt.Fprint(v, " "+repo+" → "+name) + + fmt.Fprint(v, status) return nil }) return nil } +func runeCount(str string) int { + return len([]rune(str)) +} + +func cursorInSubstring(cx int, prefix string, substring string) bool { + return cx >= runeCount(prefix) && cx < runeCount(prefix+substring) +} + func (gui *Gui) handleCheckForUpdate(g *gocui.Gui, v *gocui.View) error { gui.Updater.CheckForNewUpdate(gui.onUserUpdateCheckFinish, true) return gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("CheckingForUpdates")) } +func (gui *Gui) handleStatusClick(g *gocui.Gui, v *gocui.View) error { + state := gui.State.Panels.Status + + cx, _ := v.Cursor() + upstreamStatus := fmt.Sprintf("↑%s↓%s", state.pushables, state.pullables) + repoName := utils.GetCurrentRepoName() + gui.Log.Warn(gui.State.WorkingTreeState) + switch gui.State.WorkingTreeState { + case "rebasing", "merging": + workingTreeStatus := fmt.Sprintf("(%s)", gui.State.WorkingTreeState) + if cursorInSubstring(cx, upstreamStatus+" ", workingTreeStatus) { + return gui.handleCreateRebaseOptionsMenu(gui.g, v) + } + if cursorInSubstring(cx, upstreamStatus+" "+workingTreeStatus+" ", repoName) { + return gui.handleCreateRecentReposMenu(gui.g, v) + } + default: + if cursorInSubstring(cx, upstreamStatus+" ", repoName) { + return gui.handleCreateRecentReposMenu(gui.g, v) + } + } + + return gui.handleStatusSelect(gui.g, v) +} + func (gui *Gui) handleStatusSelect(g *gocui.Gui, v *gocui.View) error { if gui.popupPanelFocused() { return nil @@ -57,6 +94,9 @@ func (gui *Gui) handleStatusSelect(g *gocui.Gui, v *gocui.View) error { if _, err := gui.g.SetCurrentView(v.Name()); err != nil { return err } + + gui.getMainView().Title = "" + magenta := color.New(color.FgMagenta) dashboardString := strings.Join( @@ -67,7 +107,7 @@ func (gui *Gui) handleStatusSelect(g *gocui.Gui, v *gocui.View) error { "Config Options: https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md", "Tutorial: https://youtu.be/VDXvbHZYeKY", "Raise an Issue: https://github.com/jesseduffield/lazygit/issues", - magenta.Sprint("Buy Jesse a coffee: https://donorbox.org/lazygit"), // caffeine ain't free + magenta.Sprint("Become a sponsor (github is matching all donations for 12 months): https://github.com/sponsors/jesseduffield"), // caffeine ain't free }, "\n\n") return gui.renderString(g, "main", dashboardString) |