mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-10 20:05:50 +02:00
Add separate UsePty flag for CmdObj
This decouples StreamOutput from whether a PTY is used. In most cases we just want to see the output in the log window, but don't have to use a PTY, e.g. for the bisect commands. This has the implication that custom commands that are using "stream: true" no longer use a PTY. In most cases that's probably a good thing, but we're going to add a separate pty config for those who really wanted this.
This commit is contained in:
parent
8cf617b683
commit
a199ed1396
2 changed files with 24 additions and 1 deletions
|
@ -22,6 +22,9 @@ type CmdObj struct {
|
||||||
// see StreamOutput()
|
// see StreamOutput()
|
||||||
streamOutput bool
|
streamOutput bool
|
||||||
|
|
||||||
|
// see UsePty()
|
||||||
|
usePty bool
|
||||||
|
|
||||||
// see IgnoreEmptyError()
|
// see IgnoreEmptyError()
|
||||||
ignoreEmptyError bool
|
ignoreEmptyError bool
|
||||||
|
|
||||||
|
@ -125,6 +128,19 @@ func (self *CmdObj) ShouldStreamOutput() bool {
|
||||||
return self.streamOutput
|
return self.streamOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when you call this, then call Run(), we'll use a PTY to run the command. Only
|
||||||
|
// has an effect if StreamOutput() was also called. Ignored on Windows.
|
||||||
|
func (self *CmdObj) UsePty() *CmdObj {
|
||||||
|
self.usePty = true
|
||||||
|
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if UsePty() was called
|
||||||
|
func (self *CmdObj) ShouldUsePty() bool {
|
||||||
|
return self.usePty
|
||||||
|
}
|
||||||
|
|
||||||
// if you call this before ShouldStreamOutput we'll consider an error with no
|
// if you call this before ShouldStreamOutput we'll consider an error with no
|
||||||
// stderr content as a non-error. Not yet supported for Run or RunWithOutput (
|
// stderr content as a non-error. Not yet supported for Run or RunWithOutput (
|
||||||
// but adding support is trivial)
|
// but adding support is trivial)
|
||||||
|
@ -172,6 +188,7 @@ func (self *CmdObj) RunAndProcessLines(onLine func(line string) (bool, error)) e
|
||||||
|
|
||||||
func (self *CmdObj) PromptOnCredentialRequest(task gocui.Task) *CmdObj {
|
func (self *CmdObj) PromptOnCredentialRequest(task gocui.Task) *CmdObj {
|
||||||
self.credentialStrategy = PROMPT
|
self.credentialStrategy = PROMPT
|
||||||
|
self.usePty = true
|
||||||
self.task = task
|
self.task = task
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
|
@ -238,7 +238,13 @@ func (self *cmdObjRunner) runAndStreamAux(
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
cmd.Stderr = io.MultiWriter(cmdWriter, &stderr)
|
cmd.Stderr = io.MultiWriter(cmdWriter, &stderr)
|
||||||
|
|
||||||
handler, err := self.getCmdHandlerPty(cmd)
|
var handler *cmdHandler
|
||||||
|
var err error
|
||||||
|
if cmdObj.ShouldUsePty() {
|
||||||
|
handler, err = self.getCmdHandlerPty(cmd)
|
||||||
|
} else {
|
||||||
|
handler, err = self.getCmdHandlerNonPty(cmd)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue