2018-08-13 12:26:02 +02:00
|
|
|
package gui
|
2018-06-02 00:35:49 +02:00
|
|
|
|
|
|
|
import (
|
2018-08-06 07:37:14 +02:00
|
|
|
"fmt"
|
2018-09-23 06:13:10 +02:00
|
|
|
"strings"
|
2018-06-02 00:35:49 +02:00
|
|
|
|
2018-08-06 07:37:14 +02:00
|
|
|
"github.com/fatih/color"
|
|
|
|
"github.com/jesseduffield/gocui"
|
2018-08-13 13:16:21 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
2018-06-02 00:35:49 +02:00
|
|
|
)
|
|
|
|
|
2018-08-13 13:16:21 +02:00
|
|
|
func (gui *Gui) refreshStatus(g *gocui.Gui) error {
|
2018-08-06 07:37:14 +02:00
|
|
|
v, err := g.View("status")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
// for some reason if this isn't wrapped in an update the clear seems to
|
|
|
|
// be applied after the other things or something like that; the panel's
|
|
|
|
// contents end up cleared
|
|
|
|
g.Update(func(*gocui.Gui) error {
|
|
|
|
v.Clear()
|
2018-12-07 09:52:31 +02:00
|
|
|
pushables, pullables := gui.GitCommand.GetCurrentBranchUpstreamDifferenceCount()
|
2018-08-06 07:37:14 +02:00
|
|
|
fmt.Fprint(v, "↑"+pushables+"↓"+pullables)
|
2018-08-13 13:16:21 +02:00
|
|
|
branches := gui.State.Branches
|
2018-12-05 13:30:10 +02:00
|
|
|
if err := gui.updateWorkTreeState(); err != nil {
|
2018-08-06 07:37:14 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-12-05 13:30:10 +02:00
|
|
|
if gui.State.WorkingTreeState != "normal" {
|
|
|
|
fmt.Fprint(v, utils.ColoredString(fmt.Sprintf(" (%s)", gui.State.WorkingTreeState), color.FgYellow))
|
2018-08-06 07:37:14 +02:00
|
|
|
}
|
2018-08-11 07:09:37 +02:00
|
|
|
|
2018-08-06 07:37:14 +02:00
|
|
|
if len(branches) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
branch := branches[0]
|
2018-08-13 13:16:21 +02:00
|
|
|
name := utils.ColoredString(branch.Name, branch.GetColor())
|
|
|
|
repo := utils.GetCurrentRepoName()
|
2018-08-11 07:09:37 +02:00
|
|
|
fmt.Fprint(v, " "+repo+" → "+name)
|
2018-08-06 07:37:14 +02:00
|
|
|
return nil
|
|
|
|
})
|
2018-06-02 00:35:49 +02:00
|
|
|
|
2018-08-06 07:37:14 +02:00
|
|
|
return nil
|
2018-06-02 00:35:49 +02:00
|
|
|
}
|
2018-08-18 06:52:01 +02:00
|
|
|
|
2018-08-25 07:55:49 +02:00
|
|
|
func (gui *Gui) handleCheckForUpdate(g *gocui.Gui, v *gocui.View) error {
|
2018-08-27 12:08:10 +02:00
|
|
|
gui.Updater.CheckForNewUpdate(gui.onUserUpdateCheckFinish, true)
|
2019-02-16 03:03:22 +02:00
|
|
|
return gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("CheckingForUpdates"))
|
2018-08-25 07:55:49 +02:00
|
|
|
}
|
|
|
|
|
2018-08-18 06:52:01 +02:00
|
|
|
func (gui *Gui) handleStatusSelect(g *gocui.Gui, v *gocui.View) error {
|
2019-02-25 13:11:35 +02:00
|
|
|
if gui.popupPanelFocused() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := gui.g.SetCurrentView(v.Name()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-12-08 07:54:54 +02:00
|
|
|
magenta := color.New(color.FgMagenta)
|
2018-12-07 09:52:31 +02:00
|
|
|
|
2018-09-23 06:13:10 +02:00
|
|
|
dashboardString := strings.Join(
|
|
|
|
[]string{
|
|
|
|
lazygitTitle(),
|
|
|
|
"Copyright (c) 2018 Jesse Duffield",
|
|
|
|
"Keybindings: https://github.com/jesseduffield/lazygit/blob/master/docs/Keybindings.md",
|
|
|
|
"Config Options: https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md",
|
2018-11-03 10:19:47 +02:00
|
|
|
"Tutorial: https://youtu.be/VDXvbHZYeKY",
|
2018-09-23 06:13:10 +02:00
|
|
|
"Raise an Issue: https://github.com/jesseduffield/lazygit/issues",
|
2018-12-08 07:54:54 +02:00
|
|
|
magenta.Sprint("Buy Jesse a coffee: https://donorbox.org/lazygit"), // caffeine ain't free
|
2018-09-23 06:13:10 +02:00
|
|
|
}, "\n\n")
|
2018-08-18 07:30:56 +02:00
|
|
|
|
2018-12-04 10:50:11 +02:00
|
|
|
return gui.renderString(g, "main", dashboardString)
|
2018-08-18 06:52:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleOpenConfig(g *gocui.Gui, v *gocui.View) error {
|
2018-08-23 21:05:09 +02:00
|
|
|
return gui.openFile(gui.Config.GetUserConfig().ConfigFileUsed())
|
2018-08-18 06:52:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleEditConfig(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
filename := gui.Config.GetUserConfig().ConfigFileUsed()
|
2018-08-31 10:43:54 +02:00
|
|
|
return gui.editFile(filename)
|
2018-08-18 06:52:01 +02:00
|
|
|
}
|
2018-08-18 07:30:56 +02:00
|
|
|
|
|
|
|
func lazygitTitle() string {
|
|
|
|
return `
|
|
|
|
_ _ _
|
|
|
|
| | (_) |
|
|
|
|
| | __ _ _____ _ __ _ _| |_
|
|
|
|
| |/ _` + "`" + ` |_ / | | |/ _` + "`" + ` | | __|
|
|
|
|
| | (_| |/ /| |_| | (_| | | |_
|
|
|
|
|_|\__,_/___|\__, |\__, |_|\__|
|
|
|
|
__/ | __/ |
|
|
|
|
|___/ |___/ `
|
|
|
|
}
|
2018-12-08 07:54:54 +02:00
|
|
|
|
|
|
|
func (gui *Gui) updateWorkTreeState() error {
|
|
|
|
merging, err := gui.GitCommand.IsInMergeState()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if merging {
|
|
|
|
gui.State.WorkingTreeState = "merging"
|
|
|
|
return nil
|
|
|
|
}
|
2019-02-24 02:03:14 +02:00
|
|
|
isRebasing, err := gui.GitCommand.IsInRebasingState()
|
2018-12-08 07:54:54 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-02-24 02:03:14 +02:00
|
|
|
if isRebasing {
|
2018-12-08 07:54:54 +02:00
|
|
|
gui.State.WorkingTreeState = "rebasing"
|
2019-02-24 02:03:14 +02:00
|
|
|
} else {
|
|
|
|
gui.State.WorkingTreeState = "normal"
|
2018-12-08 07:54:54 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|