You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was testing "AsyncInteractChannels". When using:
send, receiver := child.AsyncInteractChannels()
Somehow the output looks buffered or waiting on lines '\n'. Would it be possible to create a version without buffering? So each character is passed without delay. Example code:
package main
import (
"bufio"
"fmt"
"os"
"time"
"github.com/ThomasRooney/gexpect"
)
func main() {
// open program
child, err := gexpect.Spawn("/bin/sh")
if err != nil {
panic("could not open program " + err.Error())
}
defer child.Close()
// open in/out channels
doCommand, receiver := child.AsyncInteractChannels()
doneChan := make(chan bool)
tickChan := time.NewTicker(time.Millisecond * 10000).C
// keyboard
reader := bufio.NewReader(os.Stdin)
keyboard := make(chan string)
go func(keyboard chan string) {
for {
s, _, err := reader.ReadRune()
if err != nil {
close(keyboard)
return
}
keyboard <- string(s)
}
}(keyboard)
// the loop
for {
select {
case msg, open := <-receiver:
if !open {
return
}
fmt.Printf("%s\n", msg)
case <-tickChan:
doCommand <- "echo example trigger 1000 seconds\n"
case commandline := <-keyboard:
doCommand <- commandline
case <-doneChan:
fmt.Println("Done")
return
}
}
}
Regards, Arjen
The text was updated successfully, but these errors were encountered:
Hi,
I was testing "AsyncInteractChannels". When using:
send, receiver := child.AsyncInteractChannels()
Somehow the output looks buffered or waiting on lines '\n'. Would it be possible to create a version without buffering? So each character is passed without delay. Example code:
Regards, Arjen
The text was updated successfully, but these errors were encountered: