fermyon / spin

Spin is the open source developer tool for building and running serverless applications powered by WebAssembly.
https://developer.fermyon.com/spin
Apache License 2.0
5.25k stars 249 forks source link

Terminating the app while a prompt is waiting will not restore terminal settings #2557

Open lann opened 4 months ago

lann commented 4 months ago

From https://github.com/fermyon/spin/discussions/2555:

Any time the spin program displays a prompt, waiting for a single keypress, it hides the cursor, e.g.

Are you sure you want to continue? [Y/n]

If I press ⌃C instead of pressing y or n, then the program aborts, but the cursor remains invisible (I'm using iTerm2.app on macOS).

I believe this could be fixed by hooking SIGINT (as we do for spin up via the ctrlc crate) and calling https://docs.rs/console/0.15.7/console/struct.Term.html#method.show_cursor (via dialoguer::console).

lann commented 4 months ago

cc @jandubois

itowlson commented 4 months ago

There is some activity on this over at dialoguer, but kind of inconclusive at the moment https://github.com/console-rs/dialoguer/issues/294

itowlson commented 4 months ago

Sigh. Showing the cursor makes it display Error: read interrupted on a Ctrl+C. From the issue it seems like we might need to handle this on every dialoguer error. ~I will... see if we can not.~ Except... in Ctrl+C you don't get to go down an error path. I am not sure what is going on in those suggestions.

itowlson commented 4 months ago

Ha ha, but setting up the handler at the top level prevents us from Ctrl+C-ing out of normal prompts, it just goes round in a loop with "Invalid value: read interrupted".