I have a REPL app in Go that should react to keyboard press events (distinct action for each key pressed key) but ReadString
expects for return key to be pressed before reading os.Stdin
:
import (
"bufio"
"os"
)
for {
reader := bufio.NewReader(os.Stdin)
key, _ := reader.ReadString('
')
deferKey(key)
}
How can I react to key press events in Go?