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

前端 未结 6 1698
甜味超标
甜味超标 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条回答
  •  Happy的楠姐
    2020-12-08 20:47

    go-termbox is very heavyweight. It wants to take over the entire terminal window. For example, it clears the screen on startup, which may not be what you want.

    I put this together on OSX. Just a tiny getchar():

    https://github.com/paulrademacher/climenu/blob/master/getchar.go

提交回复
热议问题