1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-23 22:24:51 +02:00

Mid refactor change some more stuff

This commit is contained in:
Andrei Miulescu
2018-08-12 21:04:47 +10:00
parent e65ddd7b6f
commit e8eb78617c
16 changed files with 220 additions and 118 deletions

View File

@@ -5,6 +5,9 @@ import (
// "io"
// "io/ioutil"
"errors"
"log"
"os/exec"
"runtime"
"strings"
"time"
@@ -19,6 +22,13 @@ import (
// OverlappingEdges determines if panel edges overlap
var OverlappingEdges = false
// ErrSubprocess tells us we're switching to a subprocess so we need to
// close the Gui until it is finished
var (
ErrSubprocess = errors.New("running subprocess")
subprocess *exec.Cmd
)
type stateType struct {
GitFiles []git.File
Branches []git.Branch
@@ -273,6 +283,20 @@ func resizePopupPanels(g *gocui.Gui) error {
return nil
}
func RunWithSubprocesses() {
for {
if err := run(); err != nil {
if err == gocui.ErrQuit {
break
} else if err == ErrSubprocess {
subprocess.Run()
} else {
log.Panicln(err)
}
}
}
}
func run() (err error) {
g, err := gocui.NewGui(gocui.OutputNormal, OverlappingEdges)
if err != nil {

View File

@@ -1,4 +1,4 @@
package main
package panels
import (
"fmt"
@@ -123,7 +123,8 @@ func refreshBranches(g *gocui.Gui) error {
if err != nil {
panic(err)
}
state.Branches = git.GetGitBranches()
builder := git.newBranchListBuilder() // TODO: add constructor params
state.Branches = builder.build()
v.Clear()
for _, branch := range state.Branches {
fmt.Fprintln(v, branch.getDisplayString())

View File

@@ -1,4 +1,4 @@
package main
package panels
import "github.com/jesseduffield/gocui"

View File

@@ -1,4 +1,4 @@
package main
package panels
import (
"errors"

View File

@@ -4,7 +4,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
package panels
import (
"strings"

View File

@@ -1,4 +1,4 @@
package main
package panels
import (
@@ -194,6 +194,17 @@ func handleCommitEditorPress(g *gocui.Gui, filesView *gocui.View) error {
return nil
}
func runSubprocess(g *gocui.Gui, commands string...) error {
var err error
// need this OsCommand to be available
if subprocess, err = osCommand.RunSubProcess(commands...); err != nil {
return err
}
g.Update(func(g *gocui.Gui) error {
return gui.ErrSubprocess
})
}
func genericFileOpen(g *gocui.Gui, v *gocui.View, open func(*gocui.Gui, string) (string, error)) error {
file, err := getSelectedFile(g)
if err != nil {

View File

@@ -1,6 +1,6 @@
// though this panel is called the merge panel, it's really going to use the main panel. This may change in the future
package main
package panels
import (
"bufio"

View File

@@ -1,4 +1,4 @@
package main
package panels
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package main
package panels
import (
"fmt"