1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-04 10:34:55 +02:00
lazygit/pkg/gui/gui.go

588 lines
17 KiB
Go
Raw Normal View History

package gui
2018-05-19 03:16:34 +02:00
import (
2018-12-07 20:22:22 +02:00
"sync"
2018-05-26 05:23:39 +02:00
// "io"
// "io/ioutil"
2018-05-26 05:23:39 +02:00
2018-08-12 13:04:47 +02:00
"errors"
2018-08-14 00:33:40 +02:00
"io/ioutil"
2018-08-12 13:04:47 +02:00
"log"
2018-08-14 00:33:40 +02:00
"os"
2018-08-12 13:04:47 +02:00
"os/exec"
"strings"
"time"
// "strings"
2018-08-06 08:11:29 +02:00
2018-11-25 14:15:36 +02:00
"github.com/fatih/color"
"github.com/golang-collections/collections/stack"
"github.com/jesseduffield/gocui"
2018-08-13 12:26:02 +02:00
"github.com/jesseduffield/lazygit/pkg/commands"
2018-08-18 05:22:05 +02:00
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/i18n"
2018-08-19 15:28:29 +02:00
"github.com/jesseduffield/lazygit/pkg/updates"
2018-08-25 07:55:49 +02:00
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sirupsen/logrus"
2018-05-19 03:16:34 +02:00
)
// OverlappingEdges determines if panel edges overlap
var OverlappingEdges = false
// SentinelErrors are the errors that have special meaning and need to be checked
// by calling functions. The less of these, the better
type SentinelErrors struct {
ErrSubProcess error
ErrNoFiles error
2018-09-07 01:41:15 +02:00
ErrSwitchRepo error
}
// GenerateSentinelErrors makes the sentinel errors for the gui. We're defining it here
// because we can't do package-scoped errors with localization, and also because
// it seems like package-scoped variables are bad in general
// https://dave.cheney.net/2017/06/11/go-without-package-scoped-variables
// In the future it would be good to implement some of the recommendations of
// that article. For now, if we don't need an error to be a sentinel, we will just
// define it inline. This has implications for error messages that pop up everywhere
// in that we'll be duplicating the default values. We may need to look at
// having a default localisation bundle defined, and just using keys-only when
// localising things in the code.
func (gui *Gui) GenerateSentinelErrors() {
gui.Errors = SentinelErrors{
ErrSubProcess: errors.New(gui.Tr.SLocalize("RunningSubprocess")),
ErrNoFiles: errors.New(gui.Tr.SLocalize("NoChangedFiles")),
2018-09-07 01:41:15 +02:00
ErrSwitchRepo: errors.New("switching repo"),
}
}
2018-08-14 11:05:26 +02:00
// Teml is short for template used to make the required map[string]interface{} shorter when using gui.Tr.SLocalize and gui.Tr.TemplateLocalize
2018-08-16 13:35:04 +02:00
type Teml i18n.Teml
2018-08-12 13:04:47 +02:00
2018-08-13 12:26:02 +02:00
// Gui wraps the gocui Gui object which handles rendering and events
type Gui struct {
2018-08-25 07:55:49 +02:00
g *gocui.Gui
Log *logrus.Entry
2018-08-25 07:55:49 +02:00
GitCommand *commands.GitCommand
OSCommand *commands.OSCommand
SubProcess *exec.Cmd
State guiState
Config config.AppConfigurer
Tr *i18n.Localizer
Errors SentinelErrors
Updater *updates.Updater
statusManager *statusManager
credentials credentials
2018-12-10 14:45:03 +02:00
waitForIntro sync.WaitGroup
2018-08-13 13:16:21 +02:00
}
2018-12-07 09:52:31 +02:00
// for now the staging panel state, unlike the other panel states, is going to be
// non-mutative, so that we don't accidentally end up
// with mismatches of data. We might change this in the future
type stagingPanelState struct {
SelectedLine int
StageableLines []int
HunkStarts []int
Diff string
}
type filePanelState struct {
SelectedLine int
}
type branchPanelState struct {
SelectedLine int
}
type commitPanelState struct {
SelectedLine int
}
type stashPanelState struct {
SelectedLine int
}
type menuPanelState struct {
SelectedLine int
}
type panelStates struct {
Files *filePanelState
Staging *stagingPanelState
Branches *branchPanelState
Commits *commitPanelState
Stash *stashPanelState
Menu *menuPanelState
}
2018-08-13 13:16:21 +02:00
type guiState struct {
Files []*commands.File
Branches []*commands.Branch
Commits []*commands.Commit
StashEntries []*commands.StashEntry
2018-08-13 13:16:21 +02:00
PreviousView string
HasMergeConflicts bool
ConflictIndex int
ConflictTop bool
Conflicts []commands.Conflict
EditHistory *stack.Stack
2018-08-14 04:24:32 +02:00
Platform commands.Platform
2018-08-23 10:43:16 +02:00
Updating bool
Panels *panelStates
2018-08-13 12:26:02 +02:00
}
// NewGui builds a new gui handler
func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *commands.OSCommand, tr *i18n.Localizer, config config.AppConfigurer, updater *updates.Updater) (*Gui, error) {
2018-08-13 13:16:21 +02:00
initialState := guiState{
Files: make([]*commands.File, 0),
2018-08-13 12:26:02 +02:00
PreviousView: "files",
Commits: make([]*commands.Commit, 0),
StashEntries: make([]*commands.StashEntry, 0),
2018-08-13 12:26:02 +02:00
ConflictIndex: 0,
ConflictTop: true,
Conflicts: make([]commands.Conflict, 0),
EditHistory: stack.New(),
2018-08-14 04:24:32 +02:00
Platform: *oSCommand.Platform,
Panels: &panelStates{
Files: &filePanelState{SelectedLine: -1},
Branches: &branchPanelState{SelectedLine: 0},
Commits: &commitPanelState{SelectedLine: -1},
Stash: &stashPanelState{SelectedLine: -1},
Menu: &menuPanelState{SelectedLine: 0},
},
2018-08-13 12:26:02 +02:00
}
gui := &Gui{
2018-08-25 07:55:49 +02:00
Log: log,
GitCommand: gitCommand,
OSCommand: oSCommand,
State: initialState,
Config: config,
Tr: tr,
Updater: updater,
statusManager: &statusManager{},
}
gui.GenerateSentinelErrors()
return gui, nil
2018-08-13 12:26:02 +02:00
}
2018-08-13 13:16:21 +02:00
func (gui *Gui) scrollUpMain(g *gocui.Gui, v *gocui.View) error {
mainView, _ := g.View("main")
ox, oy := mainView.Origin()
if oy >= 1 {
2018-08-18 05:22:05 +02:00
return mainView.SetOrigin(ox, oy-gui.Config.GetUserConfig().GetInt("gui.scrollHeight"))
}
return nil
2018-05-21 12:52:48 +02:00
}
2018-05-19 03:16:34 +02:00
2018-08-13 13:16:21 +02:00
func (gui *Gui) scrollDownMain(g *gocui.Gui, v *gocui.View) error {
mainView, _ := g.View("main")
ox, oy := mainView.Origin()
y := oy
if !gui.Config.GetUserConfig().GetBool("gui.scrollPastBottom") {
_, sy := mainView.Size()
y += sy
}
if y < len(mainView.BufferLines()) {
2018-08-18 05:22:05 +02:00
return mainView.SetOrigin(ox, oy+gui.Config.GetUserConfig().GetInt("gui.scrollHeight"))
}
return nil
2018-05-19 09:04:33 +02:00
}
2018-08-13 13:16:21 +02:00
func (gui *Gui) handleRefresh(g *gocui.Gui, v *gocui.View) error {
return gui.refreshSidePanels(g)
2018-06-09 11:06:33 +02:00
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
// layout is called for every screen re-render e.g. when the screen is resized
2018-08-13 12:26:02 +02:00
func (gui *Gui) layout(g *gocui.Gui) error {
g.Highlight = true
width, height := g.Size()
2018-08-20 12:52:32 +02:00
version := gui.Config.GetVersion()
leftSideWidth := width / 3
statusFilesBoundary := 2
filesBranchesBoundary := 2 * height / 5 // height - 20
commitsBranchesBoundary := 3 * height / 5 // height - 10
commitsStashBoundary := height - 5 // height - 5
2018-08-20 12:52:32 +02:00
optionsVersionBoundary := width - max(len(version), 1)
2018-08-05 14:00:02 +02:00
minimumHeight := 16
minimumWidth := 10
2018-08-05 14:00:02 +02:00
2018-08-25 07:55:49 +02:00
appStatus := gui.statusManager.getStatusString()
appStatusOptionsBoundary := 0
if appStatus != "" {
appStatusOptionsBoundary = len(appStatus) + 2
2018-08-23 10:43:16 +02:00
}
panelSpacing := 1
if OverlappingEdges {
panelSpacing = 0
}
if height < minimumHeight || width < minimumWidth {
v, err := g.SetView("limit", 0, 0, max(width-1, 2), max(height-1, 2), 0)
2018-08-05 14:00:02 +02:00
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = gui.Tr.SLocalize("NotEnoughSpace")
2018-08-05 14:00:02 +02:00
v.Wrap = true
g.SetViewOnTop("limit")
2018-08-05 14:00:02 +02:00
}
return nil
} else {
2018-12-07 09:52:31 +02:00
_, _ = g.SetViewOnBottom("limit")
2018-08-05 14:00:02 +02:00
}
2018-05-21 12:52:48 +02:00
2018-08-06 07:41:59 +02:00
g.DeleteView("limit")
optionsTop := height - 2
// hiding options if there's not enough space
if height < 30 {
optionsTop = height - 1
}
2018-05-21 12:52:48 +02:00
v, err := g.SetView("main", leftSideWidth+panelSpacing, 0, width-1, optionsTop, gocui.LEFT)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = gui.Tr.SLocalize("DiffTitle")
2018-08-05 14:00:02 +02:00
v.Wrap = true
2018-08-06 08:11:29 +02:00
v.FgColor = gocui.ColorWhite
}
2018-05-19 03:16:34 +02:00
v, err = g.SetView("staging", leftSideWidth+panelSpacing, 0, width-1, optionsTop, gocui.LEFT)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = gui.Tr.SLocalize("StagingTitle")
v.Highlight = true
v.FgColor = gocui.ColorWhite
if _, err := g.SetViewOnBottom("staging"); err != nil {
return err
}
}
2018-08-05 14:00:02 +02:00
if v, err := g.SetView("status", 0, 0, leftSideWidth, statusFilesBoundary, gocui.BOTTOM|gocui.RIGHT); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = gui.Tr.SLocalize("StatusTitle")
2018-08-06 08:11:29 +02:00
v.FgColor = gocui.ColorWhite
}
2018-06-01 15:23:31 +02:00
filesView, err := g.SetView("files", 0, statusFilesBoundary+panelSpacing, leftSideWidth, filesBranchesBoundary, gocui.TOP|gocui.BOTTOM)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
2018-08-05 14:00:02 +02:00
filesView.Highlight = true
filesView.Title = gui.Tr.SLocalize("FilesTitle")
2018-08-06 08:11:29 +02:00
v.FgColor = gocui.ColorWhite
}
2018-05-26 05:23:39 +02:00
branchesView, err := g.SetView("branches", 0, filesBranchesBoundary+panelSpacing, leftSideWidth, commitsBranchesBoundary, gocui.TOP|gocui.BOTTOM)
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
branchesView.FgColor = gocui.ColorWhite
}
2018-05-21 12:52:48 +02:00
if v, err := g.SetView("commits", 0, commitsBranchesBoundary+panelSpacing, leftSideWidth, commitsStashBoundary, gocui.TOP|gocui.BOTTOM); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = gui.Tr.SLocalize("CommitsTitle")
2018-08-06 08:11:29 +02:00
v.FgColor = gocui.ColorWhite
}
2018-06-05 10:48:46 +02:00
if v, err := g.SetView("stash", 0, commitsStashBoundary+panelSpacing, leftSideWidth, optionsTop, gocui.TOP|gocui.RIGHT); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Title = gui.Tr.SLocalize("StashTitle")
2018-08-06 08:11:29 +02:00
v.FgColor = gocui.ColorWhite
}
2018-05-21 12:52:48 +02:00
if v, err := g.SetView("options", appStatusOptionsBoundary-1, optionsTop, optionsVersionBoundary-1, optionsTop+2, 0); err != nil {
if err != gocui.ErrUnknownView {
return err
}
v.Frame = false
2018-08-18 05:54:39 +02:00
if v.FgColor, err = gui.GetOptionsPanelTextColor(); err != nil {
return err
}
2018-08-08 00:32:52 +02:00
}
2018-08-13 12:26:02 +02:00
if gui.getCommitMessageView(g) == nil {
2018-08-11 07:09:37 +02:00
// doesn't matter where this view starts because it will be hidden
2018-08-25 07:55:49 +02:00
if commitMessageView, err := g.SetView("commitMessage", 0, 0, width/2, height/2, 0); err != nil {
2018-08-11 07:09:37 +02:00
if err != gocui.ErrUnknownView {
return err
}
g.SetViewOnBottom("commitMessage")
commitMessageView.Title = gui.Tr.SLocalize("CommitMessage")
2018-08-11 07:09:37 +02:00
commitMessageView.FgColor = gocui.ColorWhite
commitMessageView.Editable = true
2018-09-02 17:08:59 +02:00
commitMessageView.Editor = gocui.EditorFunc(gui.simpleEditor)
}
2018-08-11 07:09:37 +02:00
}
if check, _ := g.View("credentials"); check == nil {
2018-10-20 17:37:55 +02:00
// doesn't matter where this view starts because it will be hidden
if credentialsView, err := g.SetView("credentials", 0, 0, width/2, height/2, 0); err != nil {
2018-10-20 17:37:55 +02:00
if err != gocui.ErrUnknownView {
return err
}
_, err := g.SetViewOnBottom("credentials")
2018-10-20 18:58:37 +02:00
if err != nil {
return err
}
2018-12-10 09:04:22 +02:00
credentialsView.Title = gui.Tr.SLocalize("CredentialsUsername")
credentialsView.FgColor = gocui.ColorWhite
credentialsView.Editable = true
credentialsView.Editor = gocui.EditorFunc(gui.simpleEditor)
2018-10-20 17:37:55 +02:00
}
}
2018-08-25 07:55:49 +02:00
if appStatusView, err := g.SetView("appStatus", -1, optionsTop, width, optionsTop+2, 0); err != nil {
2018-08-23 10:43:16 +02:00
if err != gocui.ErrUnknownView {
return err
}
2018-08-25 07:55:49 +02:00
appStatusView.BgColor = gocui.ColorDefault
appStatusView.FgColor = gocui.ColorCyan
appStatusView.Frame = false
2018-08-25 09:38:03 +02:00
if _, err := g.SetViewOnBottom("appStatus"); err != nil {
return err
}
2018-08-23 10:43:16 +02:00
}
2018-08-20 12:52:32 +02:00
if v, err := g.SetView("version", optionsVersionBoundary-1, optionsTop, width, optionsTop+2, 0); err != nil {
2018-08-08 00:32:52 +02:00
if err != gocui.ErrUnknownView {
return err
}
v.BgColor = gocui.ColorDefault
v.FgColor = gocui.ColorGreen
v.Frame = false
if err := gui.renderString(g, "version", version); err != nil {
return err
}
2018-06-05 10:48:46 +02:00
2018-08-25 07:55:49 +02:00
// these are only called once (it's a place to put all the things you want
// to happen on startup after the screen is first rendered)
2018-08-27 12:08:10 +02:00
gui.Updater.CheckForNewUpdate(gui.onBackgroundUpdateCheckFinish, false)
2018-09-07 01:41:15 +02:00
if err := gui.updateRecentRepoList(); err != nil {
return err
}
2018-12-10 14:45:03 +02:00
gui.waitForIntro.Done()
2018-09-07 01:41:15 +02:00
2018-12-07 09:52:31 +02:00
if _, err := gui.g.SetCurrentView(filesView.Name()); err != nil {
return err
}
2018-12-07 09:52:31 +02:00
if err := gui.refreshSidePanels(gui.g); err != nil {
return err
}
2018-12-07 09:52:31 +02:00
if err := gui.switchFocus(g, nil, filesView); err != nil {
return err
}
2018-08-26 07:46:18 +02:00
if gui.Config.GetUserConfig().GetString("reporting") == "undetermined" {
if err := gui.promptAnonymousReporting(); err != nil {
return err
}
}
}
2018-05-19 03:16:34 +02:00
listViews := map[*gocui.View]int{
filesView: gui.State.Panels.Files.SelectedLine,
branchesView: gui.State.Panels.Branches.SelectedLine,
}
for view, selectedLine := range listViews {
// check if the selected line is now out of view and if so refocus it
if err := gui.focusPoint(0, selectedLine, view); err != nil {
return err
}
}
2018-12-07 09:52:31 +02:00
// here is a good place log some stuff
// if you download humanlog and do tail -f development.log | humanlog
// this will let you see these branches as prettified json
// gui.Log.Info(utils.AsJson(gui.State.Branches[0:4]))
2018-09-05 11:07:46 +02:00
return gui.resizeCurrentPopupPanel(g)
2018-05-19 03:16:34 +02:00
}
2018-08-26 07:46:18 +02:00
func (gui *Gui) promptAnonymousReporting() error {
return gui.createConfirmationPanel(gui.g, nil, gui.Tr.SLocalize("AnonymousReportingTitle"), gui.Tr.SLocalize("AnonymousReportingPrompt"), func(g *gocui.Gui, v *gocui.View) error {
2018-12-10 14:45:03 +02:00
gui.waitForIntro.Done()
return gui.Config.WriteToUserConfig("reporting", "on")
2018-08-26 07:46:18 +02:00
}, func(g *gocui.Gui, v *gocui.View) error {
2018-12-10 14:45:03 +02:00
gui.waitForIntro.Done()
return gui.Config.WriteToUserConfig("reporting", "off")
2018-08-26 07:46:18 +02:00
})
}
2018-12-18 13:29:07 +02:00
func (gui *Gui) fetch(g *gocui.Gui, v *gocui.View, canAskForCredentials bool) (unamePassOpend bool, err error) {
2018-12-07 15:56:29 +02:00
unamePassOpend = false
err = gui.GitCommand.Fetch(func(passOrUname string) string {
unamePassOpend = true
2018-12-06 10:05:51 +02:00
return gui.waitForPassUname(gui.g, v, passOrUname)
2018-12-18 13:29:07 +02:00
}, canAskForCredentials)
2018-11-25 14:15:36 +02:00
2018-12-18 13:29:07 +02:00
if canAskForCredentials && err != nil && strings.Contains(err.Error(), "exit status 128") {
2018-11-25 14:15:36 +02:00
colorFunction := color.New(color.FgRed).SprintFunc()
coloredMessage := colorFunction(strings.TrimSpace(gui.Tr.SLocalize("PassUnameWrong")))
close := func(g *gocui.Gui, v *gocui.View) error {
return nil
}
2018-12-06 10:05:51 +02:00
_ = gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("Error"), coloredMessage, close, close)
2018-11-25 14:15:36 +02:00
}
2018-08-13 13:16:21 +02:00
gui.refreshStatus(g)
2018-12-07 15:56:29 +02:00
return unamePassOpend, err
2018-06-02 05:51:03 +02:00
}
2018-08-13 13:16:21 +02:00
func (gui *Gui) updateLoader(g *gocui.Gui) error {
gui.g.Update(func(g *gocui.Gui) error {
if view, _ := g.View("confirmation"); view != nil {
content := gui.trimmedContent(view)
if strings.Contains(content, "...") {
staticContent := strings.Split(content, "...")[0] + "..."
if err := gui.synchronousRenderString(g, "confirmation", staticContent+" "+utils.Loader()); err != nil {
return err
}
2018-08-23 10:43:16 +02:00
}
}
return nil
})
return nil
}
2018-08-25 07:55:49 +02:00
func (gui *Gui) renderAppStatus(g *gocui.Gui) error {
appStatus := gui.statusManager.getStatusString()
if appStatus != "" {
return gui.renderString(gui.g, "appStatus", appStatus)
}
return nil
}
2018-12-07 09:52:31 +02:00
func (gui *Gui) renderGlobalOptions() error {
return gui.renderOptionsMap(map[string]string{
"PgUp/PgDn": gui.Tr.SLocalize("scroll"),
"← → ↑ ↓": gui.Tr.SLocalize("navigate"),
"esc/q": gui.Tr.SLocalize("close"),
2018-09-05 15:55:24 +02:00
"x": gui.Tr.SLocalize("menu"),
})
}
2018-08-13 13:16:21 +02:00
func (gui *Gui) goEvery(g *gocui.Gui, interval time.Duration, function func(*gocui.Gui) error) {
go func() {
for range time.Tick(interval) {
function(g)
}
}()
}
2018-08-13 12:26:02 +02:00
// Run setup the gui with keybindings and start the mainloop
2018-08-13 13:16:21 +02:00
func (gui *Gui) Run() error {
g, err := gocui.NewGui(gocui.OutputNormal, OverlappingEdges)
if err != nil {
2018-08-13 13:16:21 +02:00
return err
}
defer g.Close()
2018-05-19 09:04:33 +02:00
2018-08-14 00:33:40 +02:00
gui.g = g // TODO: always use gui.g rather than passing g around everywhere
2018-08-18 05:53:58 +02:00
if err := gui.SetColorScheme(); err != nil {
return err
}
2018-08-11 07:09:37 +02:00
2018-12-07 20:22:22 +02:00
if gui.Config.GetUserConfig().GetString("reporting") == "undetermined" {
2018-12-10 14:45:03 +02:00
gui.waitForIntro.Add(2)
} else {
gui.waitForIntro.Add(1)
2018-12-07 20:22:22 +02:00
}
2018-11-25 14:15:36 +02:00
go func() {
2018-12-10 14:45:03 +02:00
gui.waitForIntro.Wait()
isNew := gui.Config.GetIsNewRepo()
if !isNew {
time.After(60 * time.Second)
}
2018-12-07 15:56:29 +02:00
_, err := gui.fetch(g, g.CurrentView(), false)
2018-12-10 14:45:03 +02:00
if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew {
2018-12-06 09:28:15 +02:00
_ = gui.createConfirmationPanel(g, g.CurrentView(), gui.Tr.SLocalize("NoAutomaticGitFetchTitle"), gui.Tr.SLocalize("NoAutomaticGitFetchBody"), nil, nil)
2018-12-06 09:26:05 +02:00
} else {
2018-12-02 15:58:18 +02:00
gui.goEvery(g, time.Second*60, func(g *gocui.Gui) error {
2018-12-07 15:56:29 +02:00
_, err := gui.fetch(g, g.CurrentView(), false)
return err
2018-12-02 15:58:18 +02:00
})
2018-11-25 14:15:36 +02:00
}
}()
gui.goEvery(g, time.Second*10, gui.refreshFiles)
2018-08-25 07:55:49 +02:00
gui.goEvery(g, time.Millisecond*50, gui.updateLoader)
gui.goEvery(g, time.Millisecond*50, gui.renderAppStatus)
2018-08-13 12:26:02 +02:00
g.SetManagerFunc(gui.layout)
2018-05-19 09:04:33 +02:00
2018-08-13 12:26:02 +02:00
if err = gui.keybindings(g); err != nil {
2018-08-13 13:16:21 +02:00
return err
}
2018-05-19 09:04:33 +02:00
2018-08-07 10:05:43 +02:00
err = g.MainLoop()
2018-08-13 13:16:21 +02:00
return err
2018-08-13 12:26:02 +02:00
}
// RunWithSubprocesses loops, instantiating a new gocui.Gui with each iteration
// if the error returned from a run is a ErrSubProcess, it runs the subprocess
// otherwise it handles the error, possibly by quitting the application
func (gui *Gui) RunWithSubprocesses() {
for {
if err := gui.Run(); err != nil {
if err == gocui.ErrQuit {
break
2018-09-07 01:41:15 +02:00
} else if err == gui.Errors.ErrSwitchRepo {
continue
} else if err == gui.Errors.ErrSubProcess {
2018-08-14 00:33:40 +02:00
gui.SubProcess.Stdin = os.Stdin
gui.SubProcess.Stdout = os.Stdout
gui.SubProcess.Stderr = os.Stderr
2018-08-13 12:26:02 +02:00
gui.SubProcess.Run()
2018-08-14 00:33:40 +02:00
gui.SubProcess.Stdout = ioutil.Discard
gui.SubProcess.Stderr = ioutil.Discard
gui.SubProcess.Stdin = nil
2018-08-13 13:35:54 +02:00
gui.SubProcess = nil
2018-08-13 12:26:02 +02:00
} else {
log.Panicln(err)
}
}
}
2018-05-19 09:04:33 +02:00
}
2018-08-13 13:16:21 +02:00
func (gui *Gui) quit(g *gocui.Gui, v *gocui.View) error {
2018-08-23 10:43:16 +02:00
if gui.State.Updating {
return gui.createUpdateQuitConfirmation(g, v)
}
2018-09-05 19:56:11 +02:00
if gui.Config.GetUserConfig().GetBool("confirmOnQuit") {
return gui.createConfirmationPanel(g, v, "", gui.Tr.SLocalize("ConfirmQuit"), func(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}, nil)
}
return gocui.ErrQuit
2018-05-26 05:23:39 +02:00
}