2018-08-12 11:31:27 +02:00
|
|
|
package gui
|
2018-05-19 03:16:34 +02:00
|
|
|
|
|
|
|
import (
|
2019-05-26 03:24:01 +02:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2019-03-03 14:08:07 +02:00
|
|
|
"math"
|
2019-05-18 03:28:07 +02:00
|
|
|
"os"
|
2020-01-07 04:22:15 +02:00
|
|
|
"runtime"
|
2018-12-07 20:22:22 +02:00
|
|
|
"sync"
|
2018-05-26 05:23:39 +02:00
|
|
|
|
2018-07-21 07:51:18 +02:00
|
|
|
// "io"
|
|
|
|
// "io/ioutil"
|
2018-05-26 05:23:39 +02:00
|
|
|
|
2018-08-12 13:04:47 +02:00
|
|
|
"os/exec"
|
2018-07-21 10:37:00 +02:00
|
|
|
"strings"
|
2018-07-21 07:51:18 +02:00
|
|
|
"time"
|
|
|
|
|
2019-02-11 12:30:27 +02:00
|
|
|
"github.com/go-errors/errors"
|
|
|
|
|
2018-07-21 07:51:18 +02:00
|
|
|
// "strings"
|
2018-08-06 08:11:29 +02:00
|
|
|
|
2018-11-25 14:15:36 +02:00
|
|
|
"github.com/fatih/color"
|
2018-07-21 07:51:18 +02:00
|
|
|
"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"
|
2018-08-14 15:26:25 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
2019-10-18 09:48:37 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
2018-08-19 15:28:29 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/updates"
|
2019-02-25 13:11:35 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
2020-01-07 04:22:15 +02:00
|
|
|
"github.com/mattn/go-runewidth"
|
2018-08-25 03:02:46 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-05-19 03:16:34 +02:00
|
|
|
)
|
|
|
|
|
2019-11-10 13:07:45 +02:00
|
|
|
const StartupPopupVersion = 1
|
|
|
|
|
2018-08-05 14:18:59 +02:00
|
|
|
// OverlappingEdges determines if panel edges overlap
|
|
|
|
var OverlappingEdges = false
|
2018-08-05 14:02:19 +02:00
|
|
|
|
2018-08-14 15:47:14 +02:00
|
|
|
// 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
|
2018-08-14 15:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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{
|
2018-08-16 07:16:32 +02:00
|
|
|
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 15:47:14 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-14 11:05:26 +02:00
|
|
|
|
2018-08-16 11:31:03 +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 {
|
2019-04-07 08:45:55 +02:00
|
|
|
g *gocui.Gui
|
|
|
|
Log *logrus.Entry
|
|
|
|
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
|
|
|
|
waitForIntro sync.WaitGroup
|
2020-01-08 12:02:01 +02:00
|
|
|
fileWatcher *fileWatcher
|
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
|
2019-11-05 05:21:19 +02:00
|
|
|
type lineByLinePanelState struct {
|
2019-11-04 10:47:25 +02:00
|
|
|
SelectedLineIdx int
|
|
|
|
FirstLineIdx int
|
|
|
|
LastLineIdx int
|
|
|
|
Diff string
|
|
|
|
PatchParser *commands.PatchParser
|
|
|
|
SelectMode int // one of LINE, HUNK, or RANGE
|
|
|
|
SecondaryFocused bool // this is for if we show the left or right panel
|
2018-12-04 10:50:11 +02:00
|
|
|
}
|
|
|
|
|
2018-12-08 07:54:54 +02:00
|
|
|
type mergingPanelState struct {
|
|
|
|
ConflictIndex int
|
|
|
|
ConflictTop bool
|
|
|
|
Conflicts []commands.Conflict
|
|
|
|
EditHistory *stack.Stack
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:50:11 +02:00
|
|
|
type filePanelState struct {
|
|
|
|
SelectedLine int
|
|
|
|
}
|
|
|
|
|
2019-11-13 14:18:31 +02:00
|
|
|
// TODO: consider splitting this out into the window and the branches view
|
2018-12-04 10:50:11 +02:00
|
|
|
type branchPanelState struct {
|
|
|
|
SelectedLine int
|
2019-11-13 14:18:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type remotePanelState struct {
|
|
|
|
SelectedLine int
|
2018-12-04 10:50:11 +02:00
|
|
|
}
|
|
|
|
|
2019-11-16 08:35:59 +02:00
|
|
|
type remoteBranchesState struct {
|
|
|
|
SelectedLine int
|
|
|
|
}
|
|
|
|
|
2019-11-18 00:38:36 +02:00
|
|
|
type tagsPanelState struct {
|
|
|
|
SelectedLine int
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:50:11 +02:00
|
|
|
type commitPanelState struct {
|
2019-03-23 15:46:08 +02:00
|
|
|
SelectedLine int
|
|
|
|
SpecificDiffMode bool
|
2018-12-04 10:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type stashPanelState struct {
|
|
|
|
SelectedLine int
|
|
|
|
}
|
|
|
|
|
2018-12-06 13:18:17 +02:00
|
|
|
type menuPanelState struct {
|
|
|
|
SelectedLine int
|
2019-11-10 07:20:35 +02:00
|
|
|
OnPress func(g *gocui.Gui, v *gocui.View) error
|
2018-12-06 13:18:17 +02:00
|
|
|
}
|
|
|
|
|
2019-03-09 16:42:10 +02:00
|
|
|
type commitFilesPanelState struct {
|
|
|
|
SelectedLine int
|
|
|
|
}
|
|
|
|
|
2019-11-10 07:20:35 +02:00
|
|
|
type statusPanelState struct {
|
|
|
|
pushables string
|
|
|
|
pullables string
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:50:11 +02:00
|
|
|
type panelStates struct {
|
2019-11-16 08:35:59 +02:00
|
|
|
Files *filePanelState
|
|
|
|
Branches *branchPanelState
|
|
|
|
Remotes *remotePanelState
|
|
|
|
RemoteBranches *remoteBranchesState
|
2019-11-18 00:38:36 +02:00
|
|
|
Tags *tagsPanelState
|
2019-11-16 08:35:59 +02:00
|
|
|
Commits *commitPanelState
|
|
|
|
Stash *stashPanelState
|
|
|
|
Menu *menuPanelState
|
|
|
|
LineByLine *lineByLinePanelState
|
|
|
|
Merging *mergingPanelState
|
|
|
|
CommitFiles *commitFilesPanelState
|
|
|
|
Status *statusPanelState
|
2018-12-02 10:57:01 +02:00
|
|
|
}
|
|
|
|
|
2018-08-13 13:16:21 +02:00
|
|
|
type guiState struct {
|
2019-11-12 13:19:20 +02:00
|
|
|
Files []*commands.File
|
|
|
|
Branches []*commands.Branch
|
|
|
|
Commits []*commands.Commit
|
|
|
|
StashEntries []*commands.StashEntry
|
|
|
|
CommitFiles []*commands.CommitFile
|
|
|
|
DiffEntries []*commands.Commit
|
2019-11-13 14:18:31 +02:00
|
|
|
Remotes []*commands.Remote
|
2019-11-17 01:23:06 +02:00
|
|
|
RemoteBranches []*commands.RemoteBranch
|
2019-11-18 00:38:36 +02:00
|
|
|
Tags []*commands.Tag
|
2019-11-17 01:23:06 +02:00
|
|
|
MenuItemCount int // can't store the actual list because it's of interface{} type
|
2019-11-12 13:19:20 +02:00
|
|
|
PreviousView string
|
|
|
|
Platform commands.Platform
|
|
|
|
Updating bool
|
|
|
|
Panels *panelStates
|
|
|
|
WorkingTreeState string // one of "merging", "rebasing", "normal"
|
2019-11-16 03:41:04 +02:00
|
|
|
MainContext string // used to keep the main and secondary views' contexts in sync
|
2019-11-12 13:19:20 +02:00
|
|
|
CherryPickedCommits []*commands.Commit
|
|
|
|
SplitMainPanel bool
|
|
|
|
RetainOriginalDir bool
|
|
|
|
IsRefreshingFiles bool
|
|
|
|
RefreshingFilesMutex sync.Mutex
|
2018-08-13 12:26:02 +02:00
|
|
|
}
|
|
|
|
|
2019-11-04 10:47:25 +02:00
|
|
|
// for now the split view will always be on
|
|
|
|
|
2018-08-13 12:26:02 +02:00
|
|
|
// NewGui builds a new gui handler
|
2018-08-27 12:35:55 +02:00
|
|
|
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{
|
2019-02-24 08:34:19 +02:00
|
|
|
Files: make([]*commands.File, 0),
|
|
|
|
PreviousView: "files",
|
|
|
|
Commits: make([]*commands.Commit, 0),
|
|
|
|
CherryPickedCommits: make([]*commands.Commit, 0),
|
|
|
|
StashEntries: make([]*commands.StashEntry, 0),
|
2019-03-28 11:58:34 +02:00
|
|
|
DiffEntries: make([]*commands.Commit, 0),
|
2019-02-24 08:34:19 +02:00
|
|
|
Platform: *oSCommand.Platform,
|
2018-12-04 10:50:11 +02:00
|
|
|
Panels: &panelStates{
|
2019-11-16 08:35:59 +02:00
|
|
|
Files: &filePanelState{SelectedLine: -1},
|
|
|
|
Branches: &branchPanelState{SelectedLine: 0},
|
|
|
|
Remotes: &remotePanelState{SelectedLine: 0},
|
|
|
|
RemoteBranches: &remoteBranchesState{SelectedLine: -1},
|
2019-11-18 00:38:36 +02:00
|
|
|
Tags: &tagsPanelState{SelectedLine: -1},
|
2019-11-16 08:35:59 +02:00
|
|
|
Commits: &commitPanelState{SelectedLine: -1},
|
|
|
|
CommitFiles: &commitFilesPanelState{SelectedLine: -1},
|
|
|
|
Stash: &stashPanelState{SelectedLine: -1},
|
|
|
|
Menu: &menuPanelState{SelectedLine: 0},
|
2018-12-08 07:54:54 +02:00
|
|
|
Merging: &mergingPanelState{
|
|
|
|
ConflictIndex: 0,
|
|
|
|
ConflictTop: true,
|
|
|
|
Conflicts: []commands.Conflict{},
|
|
|
|
EditHistory: stack.New(),
|
|
|
|
},
|
2019-11-10 07:20:35 +02:00
|
|
|
Status: &statusPanelState{},
|
2018-12-04 10:50:11 +02:00
|
|
|
},
|
2018-08-13 12:26:02 +02:00
|
|
|
}
|
|
|
|
|
2018-08-14 15:47:14 +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{},
|
2018-08-14 15:47:14 +02:00
|
|
|
}
|
|
|
|
|
2019-11-12 13:19:20 +02:00
|
|
|
gui.watchFilesForChanges()
|
|
|
|
|
2018-08-14 15:47:14 +02:00
|
|
|
gui.GenerateSentinelErrors()
|
|
|
|
|
|
|
|
return gui, nil
|
2018-08-13 12:26:02 +02:00
|
|
|
}
|
|
|
|
|
2019-11-10 07:50:36 +02:00
|
|
|
func (gui *Gui) scrollUpView(viewName string) error {
|
|
|
|
mainView, _ := gui.g.View(viewName)
|
2018-07-21 07:51:18 +02:00
|
|
|
ox, oy := mainView.Origin()
|
2019-03-03 14:08:07 +02:00
|
|
|
newOy := int(math.Max(0, float64(oy-gui.Config.GetUserConfig().GetInt("gui.scrollHeight"))))
|
|
|
|
return mainView.SetOrigin(ox, newOy)
|
2018-05-21 12:52:48 +02:00
|
|
|
}
|
2018-05-19 03:16:34 +02:00
|
|
|
|
2019-11-10 07:50:36 +02:00
|
|
|
func (gui *Gui) scrollDownView(viewName string) error {
|
|
|
|
mainView, _ := gui.g.View(viewName)
|
2018-07-21 07:51:18 +02:00
|
|
|
ox, oy := mainView.Origin()
|
2018-11-08 12:35:05 +02:00
|
|
|
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"))
|
2018-07-21 07:51:18 +02:00
|
|
|
}
|
|
|
|
return nil
|
2018-05-19 09:04:33 +02:00
|
|
|
}
|
|
|
|
|
2019-11-10 07:50:36 +02:00
|
|
|
func (gui *Gui) scrollUpMain(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return gui.scrollUpView("main")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) scrollDownMain(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return gui.scrollDownView("main")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) scrollUpSecondary(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return gui.scrollUpView("secondary")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) scrollDownSecondary(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
return gui.scrollDownView("secondary")
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-08-09 11:49:36 +02:00
|
|
|
func max(a, b int) int {
|
|
|
|
if a > b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2019-02-16 03:07:27 +02:00
|
|
|
// getFocusLayout returns a manager function for when view gain and lose focus
|
|
|
|
func (gui *Gui) getFocusLayout() func(g *gocui.Gui) error {
|
2019-03-11 04:04:08 +02:00
|
|
|
var previousView *gocui.View
|
2019-02-16 03:07:27 +02:00
|
|
|
return func(g *gocui.Gui) error {
|
2019-03-11 04:04:08 +02:00
|
|
|
newView := gui.g.CurrentView()
|
|
|
|
if err := gui.onFocusChange(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// for now we don't consider losing focus to a popup panel as actually losing focus
|
|
|
|
if newView != previousView && !gui.isPopupPanel(newView.Name()) {
|
|
|
|
if err := gui.onFocusLost(previousView, newView); err != nil {
|
2019-02-16 03:07:27 +02:00
|
|
|
return err
|
|
|
|
}
|
2019-03-11 04:04:08 +02:00
|
|
|
if err := gui.onFocus(newView); err != nil {
|
2019-02-16 03:07:27 +02:00
|
|
|
return err
|
|
|
|
}
|
2019-03-11 04:04:08 +02:00
|
|
|
previousView = newView
|
2019-02-16 03:07:27 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-16 12:01:17 +02:00
|
|
|
func (gui *Gui) onFocusChange() error {
|
|
|
|
currentView := gui.g.CurrentView()
|
|
|
|
for _, view := range gui.g.Views() {
|
|
|
|
view.Highlight = view == currentView
|
|
|
|
}
|
2019-11-10 07:20:35 +02:00
|
|
|
return nil
|
2019-02-16 12:01:17 +02:00
|
|
|
}
|
|
|
|
|
2019-03-11 04:04:08 +02:00
|
|
|
func (gui *Gui) onFocusLost(v *gocui.View, newView *gocui.View) error {
|
2019-02-16 03:07:27 +02:00
|
|
|
if v == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2019-11-01 00:37:27 +02:00
|
|
|
switch v.Name() {
|
|
|
|
case "branches":
|
2019-11-17 00:42:17 +02:00
|
|
|
if v.Context == "local-branches" {
|
|
|
|
// This stops the branches panel from showing the upstream/downstream changes to the selected branch, when it loses focus
|
|
|
|
// inside renderListPanel it checks to see if the panel has focus
|
|
|
|
if err := gui.renderListPanel(gui.getBranchesView(), gui.State.Branches); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-02-16 12:30:29 +02:00
|
|
|
}
|
2019-11-01 00:37:27 +02:00
|
|
|
case "main":
|
2019-03-11 00:28:47 +02:00
|
|
|
// if we have lost focus to a first-class panel, we need to do some cleanup
|
2019-11-16 03:41:04 +02:00
|
|
|
if err := gui.changeMainViewsContext("normal"); err != nil {
|
2019-03-02 04:22:02 +02:00
|
|
|
return err
|
|
|
|
}
|
2019-11-01 00:37:27 +02:00
|
|
|
case "commitFiles":
|
2019-11-16 03:41:04 +02:00
|
|
|
if gui.State.MainContext != "patch-building" {
|
2019-11-05 08:57:59 +02:00
|
|
|
if _, err := gui.g.SetViewOnBottom(v.Name()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-03-12 10:20:19 +02:00
|
|
|
}
|
2019-02-16 06:17:44 +02:00
|
|
|
}
|
2019-02-16 03:07:27 +02:00
|
|
|
gui.Log.Info(v.Name() + " focus lost")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) onFocus(v *gocui.View) error {
|
|
|
|
if v == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
gui.Log.Info(v.Name() + " focus gained")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-09 11:49:36 +02:00
|
|
|
// 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 {
|
2018-07-21 07:51:18 +02:00
|
|
|
g.Highlight = true
|
|
|
|
width, height := g.Size()
|
2019-04-20 15:56:23 +02:00
|
|
|
|
2019-03-03 05:28:16 +02:00
|
|
|
information := gui.Config.GetVersion()
|
|
|
|
if gui.g.Mouse {
|
|
|
|
donate := color.New(color.FgMagenta, color.Underline).Sprint(gui.Tr.SLocalize("Donate"))
|
|
|
|
information = donate + " " + information
|
|
|
|
}
|
2019-04-20 15:56:23 +02:00
|
|
|
|
2019-04-26 08:24:14 +02:00
|
|
|
minimumHeight := 9
|
2019-04-20 15:56:23 +02:00
|
|
|
minimumWidth := 10
|
|
|
|
if height < minimumHeight || width < minimumWidth {
|
2019-05-07 08:47:41 +02:00
|
|
|
v, err := g.SetView("limit", 0, 0, width-1, height-1, 0)
|
2019-04-20 15:56:23 +02:00
|
|
|
if err != nil {
|
|
|
|
if err.Error() != "unknown view" {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
v.Title = gui.Tr.SLocalize("NotEnoughSpace")
|
|
|
|
v.Wrap = true
|
2019-04-20 16:51:50 +02:00
|
|
|
_, _ = g.SetViewOnTop("limit")
|
2019-04-20 15:56:23 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-05 15:57:35 +02:00
|
|
|
currView := gui.g.CurrentView()
|
2019-05-06 20:04:54 +02:00
|
|
|
currentCyclebleView := gui.State.PreviousView
|
|
|
|
if currView != nil {
|
2019-05-05 15:57:35 +02:00
|
|
|
viewName := currView.Name()
|
|
|
|
usePreviouseView := true
|
|
|
|
for _, view := range cyclableViews {
|
|
|
|
if view == viewName {
|
|
|
|
currentCyclebleView = viewName
|
|
|
|
usePreviouseView = false
|
|
|
|
break
|
2019-04-20 15:56:23 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-05 15:57:35 +02:00
|
|
|
if usePreviouseView {
|
|
|
|
currentCyclebleView = gui.State.PreviousView
|
|
|
|
}
|
|
|
|
}
|
2019-04-20 15:56:23 +02:00
|
|
|
|
2019-05-05 15:57:35 +02:00
|
|
|
usableSpace := height - 7
|
|
|
|
extraSpace := usableSpace - (usableSpace/3)*3
|
|
|
|
|
|
|
|
vHeights := map[string]int{
|
|
|
|
"status": 3,
|
|
|
|
"files": (usableSpace / 3) + extraSpace,
|
|
|
|
"branches": usableSpace / 3,
|
|
|
|
"commits": usableSpace / 3,
|
|
|
|
"stash": 3,
|
|
|
|
"options": 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
if height < 28 {
|
|
|
|
defaultHeight := 3
|
2019-04-25 21:37:19 +02:00
|
|
|
if height < 21 {
|
2019-05-05 15:57:35 +02:00
|
|
|
defaultHeight = 1
|
2019-04-20 15:56:23 +02:00
|
|
|
}
|
2019-05-05 15:57:35 +02:00
|
|
|
vHeights = map[string]int{
|
|
|
|
"status": defaultHeight,
|
|
|
|
"files": defaultHeight,
|
|
|
|
"branches": defaultHeight,
|
|
|
|
"commits": defaultHeight,
|
|
|
|
"stash": defaultHeight,
|
|
|
|
"options": defaultHeight,
|
|
|
|
}
|
2019-05-06 20:04:54 +02:00
|
|
|
vHeights[currentCyclebleView] = height - defaultHeight*4 - 1
|
2019-04-20 15:56:23 +02:00
|
|
|
}
|
|
|
|
|
2019-03-03 05:28:16 +02:00
|
|
|
optionsVersionBoundary := width - max(len(utils.Decolorise(information)), 1)
|
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
|
|
|
}
|
|
|
|
|
2018-08-05 14:18:59 +02:00
|
|
|
panelSpacing := 1
|
|
|
|
if OverlappingEdges {
|
|
|
|
panelSpacing = 0
|
|
|
|
}
|
|
|
|
|
2019-03-03 05:28:16 +02:00
|
|
|
_, _ = g.SetViewOnBottom("limit")
|
2018-08-06 07:41:59 +02:00
|
|
|
g.DeleteView("limit")
|
|
|
|
|
2019-10-18 09:48:37 +02:00
|
|
|
textColor := theme.GocuiDefaultTextColor
|
2019-10-30 11:23:25 +02:00
|
|
|
leftSideWidth := width / 3
|
|
|
|
panelSplitX := width - 1
|
|
|
|
if gui.State.SplitMainPanel {
|
|
|
|
units := 7
|
|
|
|
leftSideWidth = width / units
|
|
|
|
panelSplitX = (1 + ((units - 1) / 2)) * width / units
|
|
|
|
}
|
|
|
|
|
|
|
|
main := "main"
|
|
|
|
secondary := "secondary"
|
2019-11-05 05:21:19 +02:00
|
|
|
swappingMainPanels := gui.State.Panels.LineByLine != nil && gui.State.Panels.LineByLine.SecondaryFocused
|
2019-10-30 11:23:25 +02:00
|
|
|
if swappingMainPanels {
|
|
|
|
main = "secondary"
|
|
|
|
secondary = "main"
|
|
|
|
}
|
|
|
|
|
|
|
|
v, err := g.SetView(main, leftSideWidth+panelSpacing, 0, panelSplitX, height-2, gocui.LEFT)
|
2018-07-21 07:51:18 +02:00
|
|
|
if err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-07-21 07:51:18 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-08-16 07:16:32 +02:00
|
|
|
v.Title = gui.Tr.SLocalize("DiffTitle")
|
2018-08-05 14:00:02 +02:00
|
|
|
v.Wrap = true
|
2019-10-18 09:48:37 +02:00
|
|
|
v.FgColor = textColor
|
2018-07-21 07:51:18 +02:00
|
|
|
}
|
2018-05-19 03:16:34 +02:00
|
|
|
|
2019-10-30 11:23:25 +02:00
|
|
|
hiddenViewOffset := 0
|
|
|
|
if !gui.State.SplitMainPanel {
|
|
|
|
hiddenViewOffset = 9999
|
|
|
|
}
|
|
|
|
secondaryView, err := g.SetView(secondary, panelSplitX+1+hiddenViewOffset, hiddenViewOffset, width-1+hiddenViewOffset, height-2+hiddenViewOffset, gocui.LEFT)
|
|
|
|
if err != nil {
|
|
|
|
if err.Error() != "unknown view" {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
secondaryView.Title = gui.Tr.SLocalize("DiffTitle")
|
|
|
|
secondaryView.Wrap = true
|
|
|
|
secondaryView.FgColor = gocui.ColorWhite
|
|
|
|
}
|
|
|
|
|
2019-05-05 15:57:35 +02:00
|
|
|
if v, err := g.SetView("status", 0, 0, leftSideWidth, vHeights["status"]-1, gocui.BOTTOM|gocui.RIGHT); err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-07-21 07:51:18 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-08-16 07:16:32 +02:00
|
|
|
v.Title = gui.Tr.SLocalize("StatusTitle")
|
2019-10-18 09:48:37 +02:00
|
|
|
v.FgColor = textColor
|
2018-07-21 07:51:18 +02:00
|
|
|
}
|
2018-06-01 15:23:31 +02:00
|
|
|
|
2019-05-05 15:57:35 +02:00
|
|
|
filesView, err := g.SetViewBeneath("files", "status", vHeights["files"])
|
2018-07-21 07:51:18 +02:00
|
|
|
if err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-07-21 07:51:18 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-08-05 14:00:02 +02:00
|
|
|
filesView.Highlight = true
|
2018-08-16 07:16:32 +02:00
|
|
|
filesView.Title = gui.Tr.SLocalize("FilesTitle")
|
2019-10-18 09:48:37 +02:00
|
|
|
v.FgColor = textColor
|
2018-07-21 07:51:18 +02:00
|
|
|
}
|
2018-05-26 05:23:39 +02:00
|
|
|
|
2019-05-05 15:57:35 +02:00
|
|
|
branchesView, err := g.SetViewBeneath("branches", "files", vHeights["branches"])
|
2018-12-04 10:50:11 +02:00
|
|
|
if err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-07-21 07:51:18 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-12-04 10:50:11 +02:00
|
|
|
branchesView.Title = gui.Tr.SLocalize("BranchesTitle")
|
2019-11-18 00:38:36 +02:00
|
|
|
branchesView.Tabs = []string{"Local Branches", "Remotes", "Tags"}
|
2019-10-18 09:48:37 +02:00
|
|
|
branchesView.FgColor = textColor
|
2018-07-21 07:51:18 +02:00
|
|
|
}
|
2018-05-21 12:52:48 +02:00
|
|
|
|
2019-05-05 15:57:35 +02:00
|
|
|
if v, err := g.SetViewBeneath("commitFiles", "branches", vHeights["commits"]); err != nil {
|
2019-03-09 16:42:10 +02:00
|
|
|
if err.Error() != "unknown view" {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
v.Title = gui.Tr.SLocalize("CommitFiles")
|
2019-10-18 09:48:37 +02:00
|
|
|
v.FgColor = textColor
|
2019-03-09 16:42:10 +02:00
|
|
|
}
|
|
|
|
|
2019-05-05 15:57:35 +02:00
|
|
|
commitsView, err := g.SetViewBeneath("commits", "branches", vHeights["commits"])
|
2019-02-25 13:11:35 +02:00
|
|
|
if err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-07-21 07:51:18 +02:00
|
|
|
return err
|
|
|
|
}
|
2019-02-25 13:11:35 +02:00
|
|
|
commitsView.Title = gui.Tr.SLocalize("CommitsTitle")
|
2019-10-18 09:48:37 +02:00
|
|
|
commitsView.FgColor = textColor
|
2018-07-21 07:51:18 +02:00
|
|
|
}
|
2018-06-05 10:48:46 +02:00
|
|
|
|
2019-05-05 15:57:35 +02:00
|
|
|
stashView, err := g.SetViewBeneath("stash", "commits", vHeights["stash"])
|
2019-02-25 13:11:35 +02:00
|
|
|
if err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-07-21 07:51:18 +02:00
|
|
|
return err
|
|
|
|
}
|
2019-02-25 13:11:35 +02:00
|
|
|
stashView.Title = gui.Tr.SLocalize("StashTitle")
|
2019-10-18 09:48:37 +02:00
|
|
|
stashView.FgColor = textColor
|
2018-07-21 07:51:18 +02:00
|
|
|
}
|
2018-05-21 12:52:48 +02:00
|
|
|
|
2019-05-05 15:57:35 +02:00
|
|
|
if v, err := g.SetView("options", appStatusOptionsBoundary-1, height-2, optionsVersionBoundary-1, height, 0); err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-07-21 07:51:18 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
v.Frame = false
|
2019-10-19 11:39:18 +02:00
|
|
|
userConfig := gui.Config.GetUserConfig()
|
|
|
|
v.FgColor = theme.GetColor(userConfig.GetStringSlice("gui.theme.optionsTextColor"))
|
2018-08-08 00:32:52 +02:00
|
|
|
}
|
|
|
|
|
2018-12-08 07:54:54 +02:00
|
|
|
if gui.getCommitMessageView() == nil {
|
2018-08-11 07:09:37 +02:00
|
|
|
// doesn't matter where this view starts because it will be hidden
|
2019-04-13 05:56:31 +02:00
|
|
|
if commitMessageView, err := g.SetView("commitMessage", width, height, width*2, height*2, 0); err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-08-11 07:09:37 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
g.SetViewOnBottom("commitMessage")
|
2018-08-16 07:16:32 +02:00
|
|
|
commitMessageView.Title = gui.Tr.SLocalize("CommitMessage")
|
2019-10-18 09:48:37 +02:00
|
|
|
commitMessageView.FgColor = textColor
|
2018-08-11 07:09:37 +02:00
|
|
|
commitMessageView.Editable = true
|
2019-12-07 07:10:49 +02:00
|
|
|
commitMessageView.Editor = gocui.EditorFunc(gui.commitMessageEditor)
|
2018-09-02 17:08:59 +02:00
|
|
|
}
|
2018-08-11 07:09:37 +02:00
|
|
|
}
|
|
|
|
|
2018-12-10 08:51:06 +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
|
2019-04-13 05:56:31 +02:00
|
|
|
if credentialsView, err := g.SetView("credentials", width, height, width*2, height*2, 0); err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-10-20 17:37:55 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-12-10 08:51:06 +02:00
|
|
|
_, 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")
|
2019-10-18 09:48:37 +02:00
|
|
|
credentialsView.FgColor = textColor
|
2018-12-10 08:51:06 +02:00
|
|
|
credentialsView.Editable = true
|
2018-10-20 17:37:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-06 20:04:54 +02:00
|
|
|
if appStatusView, err := g.SetView("appStatus", -1, height-2, width, height, 0); err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-08-23 10:43:16 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-05-06 20:04:54 +02:00
|
|
|
if v, err := g.SetView("information", optionsVersionBoundary-1, height-2, width, height, 0); err != nil {
|
2019-02-16 03:03:22 +02:00
|
|
|
if err.Error() != "unknown view" {
|
2018-08-08 00:32:52 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
v.BgColor = gocui.ColorDefault
|
|
|
|
v.FgColor = gocui.ColorGreen
|
|
|
|
v.Frame = false
|
2019-03-03 05:28:16 +02:00
|
|
|
if err := gui.renderString(g, "information", information); err != nil {
|
2018-08-18 06:52:01 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-06-05 10:48:46 +02:00
|
|
|
|
2019-03-12 12:43:56 +02:00
|
|
|
// doing this here because it'll only happen once
|
2019-11-16 03:41:04 +02:00
|
|
|
if err := gui.onInitialViewsCreation(); err != nil {
|
2018-09-07 01:41:15 +02:00
|
|
|
return err
|
|
|
|
}
|
2019-03-12 12:43:56 +02:00
|
|
|
}
|
2018-09-07 01:41:15 +02:00
|
|
|
|
2019-03-12 12:43:56 +02:00
|
|
|
if gui.g.CurrentView() == nil {
|
|
|
|
if _, err := gui.g.SetCurrentView(gui.getFilesView().Name()); err != nil {
|
2018-12-07 09:52:31 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-12-06 13:18:17 +02:00
|
|
|
|
2019-03-12 12:43:56 +02:00
|
|
|
if err := gui.switchFocus(gui.g, nil, gui.getFilesView()); err != nil {
|
2018-12-07 09:52:31 +02:00
|
|
|
return err
|
2018-12-04 10:50:11 +02:00
|
|
|
}
|
2019-03-12 12:43:56 +02:00
|
|
|
}
|
2018-12-07 09:52:31 +02:00
|
|
|
|
2019-03-23 02:42:19 +02:00
|
|
|
type listViewState struct {
|
|
|
|
selectedLine int
|
|
|
|
lineCount int
|
2019-11-16 07:38:38 +02:00
|
|
|
view *gocui.View
|
|
|
|
context string
|
2019-03-23 02:42:19 +02:00
|
|
|
}
|
|
|
|
|
2019-11-16 07:38:38 +02:00
|
|
|
listViews := []listViewState{
|
|
|
|
{view: filesView, context: "", selectedLine: gui.State.Panels.Files.SelectedLine, lineCount: len(gui.State.Files)},
|
|
|
|
{view: branchesView, context: "local-branches", selectedLine: gui.State.Panels.Branches.SelectedLine, lineCount: len(gui.State.Branches)},
|
|
|
|
{view: branchesView, context: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes)},
|
2019-11-16 08:35:59 +02:00
|
|
|
{view: branchesView, context: "remote-branches", selectedLine: gui.State.Panels.RemoteBranches.SelectedLine, lineCount: len(gui.State.Remotes)},
|
2019-11-16 07:38:38 +02:00
|
|
|
{view: commitsView, context: "", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits)},
|
|
|
|
{view: stashView, context: "", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries)},
|
2019-02-25 13:11:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// menu view might not exist so we check to be safe
|
|
|
|
if menuView, err := gui.g.View("menu"); err == nil {
|
2019-11-16 07:38:38 +02:00
|
|
|
listViews = append(listViews, listViewState{view: menuView, context: "", selectedLine: gui.State.Panels.Menu.SelectedLine, lineCount: gui.State.MenuItemCount})
|
2018-12-04 10:50:11 +02:00
|
|
|
}
|
2019-11-16 07:38:38 +02:00
|
|
|
for _, listView := range listViews {
|
|
|
|
// ignore views where the context doesn't match up with the selected line we're trying to focus
|
|
|
|
if listView.context != "" && (listView.view.Context != listView.context) {
|
|
|
|
continue
|
|
|
|
}
|
2018-12-04 10:50:11 +02:00
|
|
|
// check if the selected line is now out of view and if so refocus it
|
2019-11-16 07:38:38 +02:00
|
|
|
if err := gui.focusPoint(0, listView.selectedLine, listView.lineCount, listView.view); err != nil {
|
2018-12-04 10:50:11 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-11-16 03:41:04 +02:00
|
|
|
func (gui *Gui) onInitialViewsCreation() error {
|
|
|
|
if err := gui.changeMainViewsContext("normal"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-16 05:00:27 +02:00
|
|
|
gui.getBranchesView().Context = "local-branches"
|
|
|
|
|
2019-11-16 03:41:04 +02:00
|
|
|
return gui.loadNewRepo()
|
|
|
|
}
|
|
|
|
|
2019-03-12 12:43:56 +02:00
|
|
|
func (gui *Gui) loadNewRepo() error {
|
|
|
|
gui.Updater.CheckForNewUpdate(gui.onBackgroundUpdateCheckFinish, false)
|
|
|
|
if err := gui.updateRecentRepoList(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
gui.waitForIntro.Done()
|
|
|
|
|
|
|
|
if err := gui.refreshSidePanels(gui.g); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-10 13:07:45 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) showInitialPopups(tasks []func(chan struct{}) error) {
|
|
|
|
gui.waitForIntro.Add(len(tasks))
|
|
|
|
done := make(chan struct{})
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for _, task := range tasks {
|
|
|
|
go func() {
|
|
|
|
if err := task(done); err != nil {
|
|
|
|
_ = gui.createErrorPanel(gui.g, err.Error())
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
<-done
|
|
|
|
gui.waitForIntro.Done()
|
2019-03-12 12:43:56 +02:00
|
|
|
}
|
2019-11-10 13:07:45 +02:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) showShamelessSelfPromotionMessage(done chan struct{}) error {
|
|
|
|
onConfirm := func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
done <- struct{}{}
|
|
|
|
return gui.Config.WriteToUserConfig("startupPopupVersion", StartupPopupVersion)
|
2019-03-12 12:43:56 +02:00
|
|
|
}
|
2019-11-10 13:07:45 +02:00
|
|
|
|
|
|
|
return gui.createConfirmationPanel(gui.g, nil, true, gui.Tr.SLocalize("ShamelessSelfPromotionTitle"), gui.Tr.SLocalize("ShamelessSelfPromotionMessage"), onConfirm, onConfirm)
|
2019-03-12 12:43:56 +02:00
|
|
|
}
|
|
|
|
|
2019-11-10 13:07:45 +02:00
|
|
|
func (gui *Gui) promptAnonymousReporting(done chan struct{}) error {
|
2019-11-05 06:19:43 +02:00
|
|
|
return gui.createConfirmationPanel(gui.g, nil, true, gui.Tr.SLocalize("AnonymousReportingTitle"), gui.Tr.SLocalize("AnonymousReportingPrompt"), func(g *gocui.Gui, v *gocui.View) error {
|
2019-11-10 13:07:45 +02:00
|
|
|
done <- struct{}{}
|
2018-08-27 12:49:47 +02:00
|
|
|
return gui.Config.WriteToUserConfig("reporting", "on")
|
2018-08-26 07:46:18 +02:00
|
|
|
}, func(g *gocui.Gui, v *gocui.View) error {
|
2019-11-10 13:07:45 +02:00
|
|
|
done <- struct{}{}
|
2018-08-27 12:49:47 +02:00
|
|
|
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
|
|
|
|
}
|
2019-11-05 06:19:43 +02:00
|
|
|
_ = gui.createConfirmationPanel(g, v, true, 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-12-08 07:54:54 +02:00
|
|
|
func (gui *Gui) renderAppStatus() error {
|
2018-08-25 07:55:49 +02:00
|
|
|
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{
|
2020-01-07 23:26:29 +02:00
|
|
|
fmt.Sprintf("%s/%s", gui.getKeyDisplay("universal.scrollUpMain"), gui.getKeyDisplay("universal.scrollDownMain")): gui.Tr.SLocalize("scroll"),
|
|
|
|
fmt.Sprintf("%s %s %s %s", gui.getKeyDisplay("universal.prevBlock"), gui.getKeyDisplay("universal.nextBlock"), gui.getKeyDisplay("universal.prevItem"), gui.getKeyDisplay("universal.nextItem")): gui.Tr.SLocalize("navigate"),
|
|
|
|
fmt.Sprintf("%s/%s", gui.getKeyDisplay("universal.return"), gui.getKeyDisplay("universal.quit")): gui.Tr.SLocalize("close"),
|
|
|
|
fmt.Sprintf("%s", gui.getKeyDisplay("universal.optionMenu")): gui.Tr.SLocalize("menu"),
|
|
|
|
"1-5": gui.Tr.SLocalize("jump"),
|
2018-09-04 16:07:31 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-12-08 07:54:54 +02:00
|
|
|
func (gui *Gui) goEvery(interval time.Duration, function func() error) {
|
2018-08-09 11:01:42 +02:00
|
|
|
go func() {
|
|
|
|
for range time.Tick(interval) {
|
2019-03-02 04:22:02 +02:00
|
|
|
_ = function()
|
2018-08-09 11:01:42 +02:00
|
|
|
}
|
|
|
|
}()
|
2018-07-21 10:37:00 +02:00
|
|
|
}
|
|
|
|
|
2019-07-19 14:38:57 +02:00
|
|
|
func (gui *Gui) startBackgroundFetch() {
|
2019-07-19 13:56:53 +02:00
|
|
|
gui.waitForIntro.Wait()
|
|
|
|
isNew := gui.Config.GetIsNewRepo()
|
|
|
|
if !isNew {
|
|
|
|
time.After(60 * time.Second)
|
|
|
|
}
|
2019-07-19 14:40:23 +02:00
|
|
|
_, err := gui.fetch(gui.g, gui.g.CurrentView(), false)
|
2019-07-19 13:56:53 +02:00
|
|
|
if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew {
|
2019-11-05 06:19:43 +02:00
|
|
|
_ = gui.createConfirmationPanel(gui.g, gui.g.CurrentView(), true, gui.Tr.SLocalize("NoAutomaticGitFetchTitle"), gui.Tr.SLocalize("NoAutomaticGitFetchBody"), nil, nil)
|
2019-07-19 13:56:53 +02:00
|
|
|
} else {
|
|
|
|
gui.goEvery(time.Second*60, func() error {
|
|
|
|
_, err := gui.fetch(gui.g, gui.g.CurrentView(), false)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2018-08-05 14:18:59 +02:00
|
|
|
g, err := gocui.NewGui(gocui.OutputNormal, OverlappingEdges)
|
2018-07-21 07:51:18 +02:00
|
|
|
if err != nil {
|
2018-08-13 13:16:21 +02:00
|
|
|
return err
|
2018-07-21 07:51:18 +02:00
|
|
|
}
|
|
|
|
defer g.Close()
|
2018-05-19 09:04:33 +02:00
|
|
|
|
2020-01-07 04:22:15 +02:00
|
|
|
g.ASCII = runtime.GOOS == "windows" && runewidth.IsEastAsian()
|
|
|
|
|
2019-03-03 07:15:20 +02:00
|
|
|
if gui.Config.GetUserConfig().GetBool("gui.mouseEvents") {
|
|
|
|
g.Mouse = true
|
|
|
|
}
|
2019-02-25 13:11:35 +02:00
|
|
|
|
2018-08-14 00:33:40 +02:00
|
|
|
gui.g = g // TODO: always use gui.g rather than passing g around everywhere
|
|
|
|
|
2019-10-19 11:39:18 +02:00
|
|
|
if err := gui.setColorScheme(); err != nil {
|
2018-08-18 05:53:58 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-08-11 07:09:37 +02:00
|
|
|
|
2019-11-10 13:07:45 +02:00
|
|
|
popupTasks := []func(chan struct{}) error{}
|
2018-12-07 20:22:22 +02:00
|
|
|
if gui.Config.GetUserConfig().GetString("reporting") == "undetermined" {
|
2019-11-10 13:07:45 +02:00
|
|
|
popupTasks = append(popupTasks, gui.promptAnonymousReporting)
|
|
|
|
}
|
|
|
|
configPopupVersion := gui.Config.GetUserConfig().GetInt("StartupPopupVersion")
|
|
|
|
// -1 means we've disabled these popups
|
|
|
|
if configPopupVersion != -1 && configPopupVersion < StartupPopupVersion {
|
|
|
|
popupTasks = append(popupTasks, gui.showShamelessSelfPromotionMessage)
|
2018-12-07 20:22:22 +02:00
|
|
|
}
|
2019-11-10 13:07:45 +02:00
|
|
|
gui.showInitialPopups(popupTasks)
|
2018-12-07 20:22:22 +02:00
|
|
|
|
2019-11-10 13:07:45 +02:00
|
|
|
gui.waitForIntro.Add(1)
|
2019-08-06 14:47:24 +02:00
|
|
|
if gui.Config.GetUserConfig().GetBool("git.autoFetch") {
|
2019-07-19 13:56:53 +02:00
|
|
|
go gui.startBackgroundFetch()
|
|
|
|
}
|
2019-11-10 13:07:45 +02:00
|
|
|
|
2019-02-11 12:07:12 +02:00
|
|
|
gui.goEvery(time.Second*10, gui.refreshFiles)
|
|
|
|
gui.goEvery(time.Millisecond*50, gui.renderAppStatus)
|
2018-07-21 10:37:00 +02:00
|
|
|
|
2019-02-16 03:07:27 +02:00
|
|
|
g.SetManager(gocui.ManagerFunc(gui.layout), gocui.ManagerFunc(gui.getFocusLayout()))
|
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-07-21 07:51:18 +02:00
|
|
|
}
|
2018-05-19 09:04:33 +02:00
|
|
|
|
2019-11-10 13:07:45 +02:00
|
|
|
gui.Log.Warn("starting main loop")
|
|
|
|
|
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
|
2019-02-18 10:42:23 +02:00
|
|
|
func (gui *Gui) RunWithSubprocesses() error {
|
2018-08-13 12:26:02 +02:00
|
|
|
for {
|
|
|
|
if err := gui.Run(); err != nil {
|
|
|
|
if err == gocui.ErrQuit {
|
2019-10-07 03:34:12 +02:00
|
|
|
if !gui.State.RetainOriginalDir {
|
|
|
|
if err := gui.recordCurrentDirectory(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 12:02:01 +02:00
|
|
|
gui.fileWatcher.Watcher.Close()
|
2019-11-12 13:19:20 +02:00
|
|
|
|
2018-08-13 12:26:02 +02:00
|
|
|
break
|
2018-09-07 01:41:15 +02:00
|
|
|
} else if err == gui.Errors.ErrSwitchRepo {
|
|
|
|
continue
|
2018-08-14 15:47:14 +02:00
|
|
|
} else if err == gui.Errors.ErrSubProcess {
|
2019-05-26 03:24:01 +02:00
|
|
|
if err := gui.runCommand(); err != nil {
|
2019-03-12 12:43:56 +02:00
|
|
|
return err
|
|
|
|
}
|
2018-08-13 12:26:02 +02:00
|
|
|
} else {
|
2019-02-18 10:42:23 +02:00
|
|
|
return err
|
2018-08-13 12:26:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-18 10:42:23 +02:00
|
|
|
return nil
|
2018-05-19 09:04:33 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 03:24:01 +02:00
|
|
|
func (gui *Gui) runCommand() error {
|
|
|
|
gui.SubProcess.Stdout = os.Stdout
|
|
|
|
gui.SubProcess.Stderr = os.Stdout
|
|
|
|
gui.SubProcess.Stdin = os.Stdin
|
2019-03-12 12:43:56 +02:00
|
|
|
|
2019-05-26 03:24:01 +02:00
|
|
|
fmt.Fprintf(os.Stdout, "\n%s\n\n", utils.ColoredString("+ "+strings.Join(gui.SubProcess.Args, " "), color.FgBlue))
|
|
|
|
|
|
|
|
if err := gui.SubProcess.Run(); err != nil {
|
2019-03-12 12:43:56 +02:00
|
|
|
// not handling the error explicitly because usually we're going to see it
|
|
|
|
// in the output anyway
|
|
|
|
gui.Log.Error(err)
|
|
|
|
}
|
|
|
|
|
2019-05-26 03:24:01 +02:00
|
|
|
gui.SubProcess.Stdout = ioutil.Discard
|
|
|
|
gui.SubProcess.Stderr = ioutil.Discard
|
|
|
|
gui.SubProcess.Stdin = nil
|
|
|
|
gui.SubProcess = nil
|
|
|
|
|
|
|
|
fmt.Fprintf(os.Stdout, "\n%s", utils.ColoredString(gui.Tr.SLocalize("pressEnterToReturn"), color.FgGreen))
|
|
|
|
fmt.Scanln() // wait for enter press
|
|
|
|
|
|
|
|
return nil
|
2019-03-12 12:43:56 +02:00
|
|
|
}
|
|
|
|
|
2019-02-25 13:11:35 +02:00
|
|
|
func (gui *Gui) handleDonate(g *gocui.Gui, v *gocui.View) error {
|
2019-03-03 05:28:16 +02:00
|
|
|
if !gui.g.Mouse {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-25 13:11:35 +02:00
|
|
|
cx, _ := v.Cursor()
|
|
|
|
if cx > len(gui.Tr.SLocalize("Donate")) {
|
|
|
|
return nil
|
|
|
|
}
|
2019-11-10 13:07:45 +02:00
|
|
|
return gui.OSCommand.OpenLink("https://github.com/sponsors/jesseduffield")
|
2019-02-25 13:11:35 +02:00
|
|
|
}
|
2019-10-19 11:39:18 +02:00
|
|
|
|
|
|
|
// setColorScheme sets the color scheme for the app based on the user config
|
|
|
|
func (gui *Gui) setColorScheme() error {
|
|
|
|
userConfig := gui.Config.GetUserConfig()
|
|
|
|
theme.UpdateTheme(userConfig)
|
|
|
|
|
|
|
|
gui.g.FgColor = theme.InactiveBorderColor
|
|
|
|
gui.g.SelFgColor = theme.ActiveBorderColor
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2019-11-10 07:20:35 +02:00
|
|
|
|
|
|
|
func (gui *Gui) handleMouseDownMain(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
if gui.popupPanelFocused() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
switch g.CurrentView().Name() {
|
|
|
|
case "files":
|
|
|
|
return gui.enterFile(false, v.SelectedLineIdx())
|
|
|
|
case "commitFiles":
|
|
|
|
return gui.enterCommitFile(v.SelectedLineIdx())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleMouseDownSecondary(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
if gui.popupPanelFocused() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
switch g.CurrentView().Name() {
|
|
|
|
case "files":
|
|
|
|
return gui.enterFile(true, v.SelectedLineIdx())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|