Simple tty utility
tty, err := tty.Open()
if err != nil {
log.Fatal(err)
}
defer tty.Close()
for {
r, err := tty.ReadRune()
if err != nil {
log.Fatal(err)
}
// handle key event
}
if you are on windows and want to display ANSI colors, use go-colorable.
tty, err := tty.Open()
if err != nil {
log.Fatal(err)
}
defer tty.Close()
out := colorable.NewColorable(tty.Output())
fmt.Fprintln(out, "\x1b[2J")
$ go get github.com/mattn/go-tty
MIT
Yasuhiro Matsumoto (a.k.a mattn)