Skip to content

Commit a199ed1

Browse files
committed
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.
1 parent 8cf617b commit a199ed1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pkg/commands/oscommands/cmd_obj.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ type CmdObj struct {
2222
// see StreamOutput()
2323
streamOutput bool
2424

25+
// see UsePty()
26+
usePty bool
27+
2528
// see IgnoreEmptyError()
2629
ignoreEmptyError bool
2730

@@ -125,6 +128,19 @@ func (self *CmdObj) ShouldStreamOutput() bool {
125128
return self.streamOutput
126129
}
127130

131+
// when you call this, then call Run(), we'll use a PTY to run the command. Only
132+
// has an effect if StreamOutput() was also called. Ignored on Windows.
133+
func (self *CmdObj) UsePty() *CmdObj {
134+
self.usePty = true
135+
136+
return self
137+
}
138+
139+
// returns true if UsePty() was called
140+
func (self *CmdObj) ShouldUsePty() bool {
141+
return self.usePty
142+
}
143+
128144
// if you call this before ShouldStreamOutput we'll consider an error with no
129145
// stderr content as a non-error. Not yet supported for Run or RunWithOutput (
130146
// but adding support is trivial)
@@ -172,6 +188,7 @@ func (self *CmdObj) RunAndProcessLines(onLine func(line string) (bool, error)) e
172188

173189
func (self *CmdObj) PromptOnCredentialRequest(task gocui.Task) *CmdObj {
174190
self.credentialStrategy = PROMPT
191+
self.usePty = true
175192
self.task = task
176193

177194
return self

pkg/commands/oscommands/cmd_obj_runner.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,13 @@ func (self *cmdObjRunner) runAndStreamAux(
238238
var stderr bytes.Buffer
239239
cmd.Stderr = io.MultiWriter(cmdWriter, &stderr)
240240

241-
handler, err := self.getCmdHandlerPty(cmd)
241+
var handler *cmdHandler
242+
var err error
243+
if cmdObj.ShouldUsePty() {
244+
handler, err = self.getCmdHandlerPty(cmd)
245+
} else {
246+
handler, err = self.getCmdHandlerNonPty(cmd)
247+
}
242248
if err != nil {
243249
return err
244250
}

0 commit comments

Comments
 (0)