mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-11 23:40:28 -10:00
* Add managed background terminal sessions * Stop background terminals on TUI exit * Cover approved local network sandbox mode * Polish background terminal rendering * Tighten exec session cleanup guidance * Address background terminal review feedback * Kill exec session trees on Windows * Trigger CI for Windows cleanup
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package tools
|
|
|
|
import (
|
|
"io"
|
|
"os/exec"
|
|
)
|
|
|
|
func startExecProcess(command *exec.Cmd, output *execOutputBuffer, ttyRequested bool) (io.WriteCloser, bool, func(), error) {
|
|
if ttyRequested {
|
|
if stdin, cleanup, err := startPTYProcessFunc(command, output); err == nil {
|
|
return stdin, true, cleanup, nil
|
|
}
|
|
resetExecCommandForPipeFallback(command)
|
|
}
|
|
return startPipeProcess(command, output)
|
|
}
|
|
|
|
var startPTYProcessFunc = startPTYProcess
|
|
|
|
func resetExecCommandForPipeFallback(command *exec.Cmd) {
|
|
command.Stdin = nil
|
|
command.Stdout = nil
|
|
command.Stderr = nil
|
|
command.SysProcAttr = nil
|
|
command.Cancel = nil
|
|
command.WaitDelay = 0
|
|
}
|
|
|
|
func startPipeProcess(command *exec.Cmd, output *execOutputBuffer) (io.WriteCloser, bool, func(), error) {
|
|
stdin, err := command.StdinPipe()
|
|
if err != nil {
|
|
return nil, false, nil, err
|
|
}
|
|
command.Stdout = output
|
|
command.Stderr = output
|
|
hardenProcessLifetime(command)
|
|
if err := command.Start(); err != nil {
|
|
return nil, false, nil, err
|
|
}
|
|
return stdin, false, func() {}, nil
|
|
}
|