fix: wait on bash prompt ready marker before sending in keystrokes
This commit is contained in:
@@ -32,6 +32,7 @@ type RecordRequest struct {
|
||||
type ReplayRequest struct {
|
||||
Cmd *exec.Cmd
|
||||
Input []byte
|
||||
InputReady <-chan struct{}
|
||||
OutputLog io.Writer
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ func Replay(req ReplayRequest) error {
|
||||
defer ptmx.Close()
|
||||
|
||||
outputDone := copyAsync(combineWriters(req.OutputLog), ptmx)
|
||||
inputDone := copyAsync(ptmx, bytes.NewReader(replayInput(req.Input)))
|
||||
inputDone := copyAsyncWhenReady(ptmx, bytes.NewReader(replayInput(req.Input)), req.InputReady)
|
||||
|
||||
waitErr := req.Cmd.Wait()
|
||||
ptmx.Close()
|
||||
@@ -128,6 +129,18 @@ func copyAsync(dst io.Writer, src io.Reader) <-chan error {
|
||||
return done
|
||||
}
|
||||
|
||||
func copyAsyncWhenReady(dst io.Writer, src io.Reader, ready <-chan struct{}) <-chan error {
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
if ready != nil {
|
||||
<-ready
|
||||
}
|
||||
_, err := io.Copy(dst, src)
|
||||
done <- normalizeCopyError(err)
|
||||
}()
|
||||
return done
|
||||
}
|
||||
|
||||
func replayInput(input []byte) []byte {
|
||||
if len(input) > 0 && input[len(input)-1] == terminalEOF {
|
||||
return input
|
||||
|
||||
Reference in New Issue
Block a user