AlecAivazis / survey

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

restore cursor on error #337

Closed noerw closed 3 years ago

noerw commented 3 years ago

This fixes restoring the state of the cursor when an error occurs when detecting terminal size. fixes #282

Piped stdin is still not handled correctly: The problem here is, that with piped stdin, Cursor.Location() fails with io.EOF: https://github.com/AlecAivazis/survey/blob/f45c05b5039ca1f9c9c562be232f1c4044e0add0/terminal/cursor.go#L106-L109 Subsequently, no input is read, and control commands printed instead of being applied.

I'm not exactly sure how a piped stdin differs from a terminal stdin, so I don't know how to fix this. One step surely would be to change Cursor, so that it detects piped stdin, and switches to a NO-OP mode?

If this can't be fixed properly, the README should clearly state that using survey with piped stdin breaks the application.

AlecAivazis commented 3 years ago

Hey @noerw - thanks for hunting this down.

Unfortunately, i dont have a lot of time right now to hunt down a better way to address this so I'm fine with adding a notice to the README 👍