AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.07k stars 349 forks source link

Arrow keys providing garbage input under Windows #480

Closed ndarilek closed 1 year ago

ndarilek commented 1 year ago

For context, I'm working on this issue where are prompts spit out garbage control codes when someone arrows around them under Windows.

I've confirmed that the examples in this repo don't exhibit this behavior.

I think the issue is that we're passing in our own streams to survey.WithStdio and somehow these aren't correct under Windows.

I've never worked with terminals on a lower level before, so I'm unsure if these garbage characters are a symptom of inputs not being read correctly, or output not rendering the cursor movement codes correctly. I've tried passing our original output stream to terminal.NewAnsiStdout but this hasn't fixed it. This leads me to believe it might be an issue on stdin but I'm not immediately seeing any different stdin-handling when tracing the code in the examples. Also, it looks like NewAnsiStdout may be meant more for one-off writes than for ensuring that arrows move the cursor.

For context, the code in question is here. Apologies if the solution is simple--I'm new to Go and grappling a bit with its duck typing. :)

Thanks!

ndarilek commented 1 year ago

Fixed, was a bug on our end where we double-initialized the console and likely undid the initialization done by the prompt functions. Apologies for the noise.