diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-24 10:43:48 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-30 18:26:06 +1100 |
commit | f704707d291387b2c1d7432c7700fb5398432f18 (patch) | |
tree | 4d9a54fbfb789af24f49e215f70b7bfe664f1616 /pkg/gui/gpg.go | |
parent | 01d82749b17cd7a048d69c8386044d79548f7893 (diff) |
stream output from certain git commands in command log panel
Diffstat (limited to 'pkg/gui/gpg.go')
-rw-r--r-- | pkg/gui/gpg.go | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/pkg/gui/gpg.go b/pkg/gui/gpg.go index e172f3720..1811e4fb5 100644 --- a/pkg/gui/gpg.go +++ b/pkg/gui/gpg.go @@ -1,5 +1,11 @@ package gui +import ( + "fmt" + + "github.com/jesseduffield/lazygit/pkg/gui/style" +) + // Currently there is a bug where if we switch to a subprocess from within // WithWaitingStatus we get stuck there and can't return to lazygit. We could // fix this bug, or just stop running subprocesses from within there, given that @@ -19,23 +25,38 @@ func (gui *Gui) withGpgHandling(cmdStr string, waitingStatus string, onSuccess f return err } - if err != nil { - return err - } + return err } else { - return gui.WithWaitingStatus(waitingStatus, func() error { - err := gui.OSCommand.RunCommand(cmdStr) - if err != nil { - return err - } else if onSuccess != nil { - if err := onSuccess(); err != nil { - return err - } + return gui.RunAndStream(cmdStr, waitingStatus, onSuccess) + } +} + +func (gui *Gui) RunAndStream(cmdStr string, waitingStatus string, onSuccess func() error) error { + return gui.WithWaitingStatus(waitingStatus, func() error { + cmd := gui.OSCommand.ShellCommandFromString(cmdStr) + cmd.Env = append(cmd.Env, "TERM=dumb") + cmdWriter := gui.getCmdWriter() + cmd.Stdout = cmdWriter + cmd.Stderr = cmdWriter + + if err := cmd.Run(); err != nil { + if _, err := cmd.Stdout.Write([]byte(fmt.Sprintf("%s\n", style.FgRed.Sprint(err.Error())))); err != nil { + gui.Log.Error(err) } + _ = gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + return gui.surfaceError( + fmt.Errorf( + gui.Tr.GitCommandFailed, gui.Config.GetUserConfig().Keybinding.Universal.ExtrasMenu, + ), + ) + } - return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) - }) - } + if onSuccess != nil { + if err := onSuccess(); err != nil { + return err + } + } - return nil + return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + }) } |