Fix: the first key after terminal-window activated was input twice.

reported on zetamatta/nyagos#393
1 file changed
tree: 5a58d49f6390234153f610ad2cfb624657f1a9be
  1. _example/
  2. ttyutil/
  3. .travis.yml
  4. go.mod
  5. go.sum
  6. LICENSE
  7. README.md
  8. tty.go
  9. tty_bsd.go
  10. tty_linux.go
  11. tty_plan9.go
  12. tty_sys5.go
  13. tty_unix.go
  14. tty_windows.go
README.md

go-tty

Simple tty utility

Usage

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")

Installation

$ go get github.com/mattn/go-tty

License

MIT

Author

Yasuhiro Matsumoto (a.k.a mattn)