Read a character from standard input in Go (without pressing Enter)

前端 未结 6 1714
甜味超标
甜味超标 2020-12-08 20:29

I want to my app shows:

press any key to exit ...

And when I pressed any key, it exits.

How can I achieve this?

6条回答
  •  难免孤独
    2020-12-08 20:54

    You can read a single key-press from a terminal in raw mode. Here is a package that should provide raw terminal mode to your program. Catch: it's Linux only.

提交回复
热议问题