SBoudrias/Inquirer.js

Ctrl-c-ing out of checkbox prompt leaves terminal in broken state

maschwenk opened this issue · 7 comments

On@inquirer/checkbox@1.3.8

Screenshot 2023-08-23 at 11 24 32 AM

When ctrl-cing out of a prompt, the terminal cursor is left in broken state.

Cannot reproduce this with old inquirer package. Have to open a new terminal to fix.

Hi @maschwenk, can you explain what you mean by "broken state"? Broken how? What is the expected state?

Think this has to do with c51e33d downgrading cli-cursor, which causes restore-cursor to fail and not restore the cursor to the terminal prompt: sindresorhus/np#689 (comment)

Hi @tommy-mitchell, I doubt this is related. This package is only used on the legacy version; and this one doesn't have the issue of the cursor disappearing on ctrl+C.

It appears to only happen with the @inquirer/prompts version. I'm not exactly sure where the regression came from; that was reported and fixed "recently" (but since it's crtl+c/sigint, I wasn't able to add a regression test that wouldn't kill the test runner 😫)

The code restoring the cursor as a back up is here: https://github.com/SBoudrias/Inquirer.js/blob/master/packages/core/src/lib/screen-manager.mts#L128 - I wasn't able to figure it out yet.

Seems it's only the select/list prompt in my case, as it was happening with the old inquirer package as well. sigint during other prompts doesn't have the same issue.

@tommy-mitchell I'm not sure I'm fully following. Which version of the old Inquirer are you running into this issue with? I wasn't able to reproduce this myself.

I can only reproduce with those 2 prompts on @inquirer/prompts.

Hm, now I'm unable to reproduce on the old Inquirer either. It was occurring on this prompt in np: https://github.com/sindresorhus/np/blob/main/source/ui.js#L222, but now it's working correctly locally.

This should now work properly.

Not sure how it happens, but signals became 0 without names (just null.) And so the force exit handler wasn't running anymore. It could be a side-effect of the Node async hooks; but really weird. Anyway, now detection should be more reliable for the future.