mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-04 23:37:41 +02:00
factor out platform specific logic into a struct on state
This commit is contained in:
parent
ce8884f509
commit
5cc34e7801
@ -8,7 +8,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -118,20 +117,12 @@ func mergeGitStatusFiles(oldGitFiles, newGitFiles []GitFile) []GitFile {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func platformShell() (string, string) {
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
return "cmd", "/c"
|
|
||||||
}
|
|
||||||
return "bash", "-c"
|
|
||||||
}
|
|
||||||
|
|
||||||
func runDirectCommand(command string) (string, error) {
|
func runDirectCommand(command string) (string, error) {
|
||||||
timeStart := time.Now()
|
timeStart := time.Now()
|
||||||
commandLog(command)
|
commandLog(command)
|
||||||
|
|
||||||
shell, shellArg := platformShell()
|
|
||||||
cmdOut, err := exec.
|
cmdOut, err := exec.
|
||||||
Command(shell, shellArg, command).
|
Command(state.Platform.shell, state.Platform.shellArg, command).
|
||||||
CombinedOutput()
|
CombinedOutput()
|
||||||
devLog("run direct command time for command: ", command, time.Now().Sub(timeStart))
|
devLog("run direct command time for command: ", command, time.Now().Sub(timeStart))
|
||||||
return sanitisedCommandOutput(cmdOut, err)
|
return sanitisedCommandOutput(cmdOut, err)
|
||||||
|
29
gui.go
29
gui.go
@ -5,6 +5,7 @@ import (
|
|||||||
// "io"
|
// "io"
|
||||||
// "io/ioutil"
|
// "io/ioutil"
|
||||||
|
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ type stateType struct {
|
|||||||
ConflictTop bool
|
ConflictTop bool
|
||||||
Conflicts []conflict
|
Conflicts []conflict
|
||||||
EditHistory *stack.Stack
|
EditHistory *stack.Stack
|
||||||
|
Platform platform
|
||||||
}
|
}
|
||||||
|
|
||||||
type conflict struct {
|
type conflict struct {
|
||||||
@ -45,6 +47,33 @@ var state = stateType{
|
|||||||
ConflictTop: true,
|
ConflictTop: true,
|
||||||
Conflicts: make([]conflict, 0),
|
Conflicts: make([]conflict, 0),
|
||||||
EditHistory: stack.New(),
|
EditHistory: stack.New(),
|
||||||
|
Platform: getPlatform(),
|
||||||
|
}
|
||||||
|
|
||||||
|
type platform struct {
|
||||||
|
os string
|
||||||
|
shell string
|
||||||
|
shellArg string
|
||||||
|
escapedQuote string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPlatform() platform {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
return platform{
|
||||||
|
os: "windows",
|
||||||
|
shell: "cmd",
|
||||||
|
shellArg: "/c",
|
||||||
|
escapedQuote: "\\\"",
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return platform{
|
||||||
|
os: runtime.GOOS,
|
||||||
|
shell: "bash",
|
||||||
|
shellArg: "-c",
|
||||||
|
escapedQuote: "\"",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func scrollUpMain(g *gocui.Gui, v *gocui.View) error {
|
func scrollUpMain(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user