ishell
ishell copied to clipboard
Add readline timeout
Add support for timeout when reading line.
I used this workaround. I hope it will help.
func CommandHandler(c *ishell.Context) {
select {
case <-time.After(10 * time.Second):
c.Println("\n\n[[ Session timed out! ]]\n")
return
case input := <-readLine(c):
c.Println("You wrote: "+ input)
return
}
}
func readLine(c *ishell.Context) (chan string) {
inputChan := make(chan string)
go func() {
inputChan <- c.ReadLine()
}()
return inputChan
}
The main issue is the limitation with the readline library that ishell depends on. I haven't figured a way to interrupt a readline without keyboard input.
Until then, this issue may not have a proper fix.