2

In my Go program which I run on MS Windows I want to get a confirmation for a 'delete file' action with the keys y/n/a, and it's going to be repeated a big number of times. And I do not want to have to press enter for each time.

I've tried answers from Read a character from standard input in Go (without pressing Enter) without success.

  1. Answer based on exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() It is for UNIX
  2. Answer based on termbox-go , it is a bit overkill for what I need, just to read a char. I did not had the time to learn and use termbox-go
  3. getchar.go It is for OSX
  4. https://github.com/eiannone/keyboard It hangs and does not read the keystroke
  5. golang.org/x/term term.MakeRaw(int(os.Stdin.Fd())) gives the error The handle is invalid
  6. Next answer it is only for Linux
  7. The last answer does not show how to read a char

Any proposal for Windows? I find it a bit remarkable that Golang does not have a built-in method similar to getChar(), or at least in the packages io or bufio, e.g., readRune or readByte still require Enter, even when you're supposed to only read one of them.

0 Answers0