ishell icon indicating copy to clipboard operation
ishell copied to clipboard

Add readline timeout

Open neutronstein opened this issue 9 years ago • 2 comments

Add support for timeout when reading line.

neutronstein avatar Feb 06 '17 22:02 neutronstein

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
}

neutronstein avatar Feb 08 '17 11:02 neutronstein

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.

abiosoft avatar May 30 '17 20:05 abiosoft