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

Provide a way to detect if the Esc key (or any other key) has been pressed. #255

Open PrMinisterGR opened 4 years ago

PrMinisterGR commented 4 years ago

I would like to use Esc to go to different places in a loop, but the way survey intercepts it, it's currently impossible.

Thank you for your work!

dineshba commented 4 years ago

Could you give small example and some details about your usecase?

PrMinisterGR commented 4 years ago

Hey, I would love to show a multi select and be able to detect Esc (like I can do with other keys), to return err on the function running it.

AlecAivazis commented 4 years ago

Thanks for the submission @PrMinisterGR! And thanks for following up @dineshba!!

I discussed trapping esc awhile back when we adding the vim mode. I think that addition was probably a bit pre-emptive since I now thing the esc is better used to get out of options like you might be hoping to do. Unforunately, since it would introduce a breaking change to the API, i have been holding off on removing it until v3. I know this isn't quite the answer you want but it's the best I can do right now 😦

PrMinisterGR commented 4 years ago

No worries, as long as it's eventually fixed, that will be great.

skelouse commented 1 year ago

Are there any methods currently to capture escape? I notice (Ubuntu) that a selection flashes when escape is pressed.

I could implement an "ErrorOnEscape" field to the Select struct. Let me know if that would be breaking @AlecAivazis