bombshell-dev / clack

Effortlessly build beautiful command-line apps
https://clack.cc
5.25k stars 88 forks source link

[Bug] Can't handle keypresses after clack session #134

Closed Jwiggiff closed 2 weeks ago

Jwiggiff commented 11 months ago

Environment

Describe the bug I am trying to use prompts to have kind a main menu for my program. After user selects an option, I am no longer using prompts. I have code to handle key presses using readline.emitKeypressEvents(process.stdin); which was working before I added in the prompts menu beforehand, but now it no longer works. I want to be able to use prompts and then end the session and have it behave as normal.

To Reproduce https://stackblitz.com/edit/node-22pky6?file=index.js

Steps to reproduce the behavior:

Expected behavior Manual key handling works after prompts is done

cpreston321 commented 11 months ago

@Jwiggiff this issue should be fixed in the latest release 0.70.0.

If not please re-open this issue.

Thanks!

Jwiggiff commented 11 months ago

@cpreston321 Thank you for looking into this. Unfortunately, it still seems to be an issue with the new release.

https://stackblitz.com/edit/node-22pky6?file=index.js

mikenikles commented 10 months ago

I'll add this as a comment, but please let me know if you think it's a separate issue.

I recently added a spinner to my CLI and ever since, Ctrl + C is ignored after the spinner finished. I have reproduction at https://stackblitz.com/edit/clack-prompts-69ciwh?file=index.js.

Update For the issue I see with Ctrl + C, it's the SIGINT process handler here that causes it. I think once stop has been called, the SIGTERM, SIGINT, etc. handlers should be removed to let Node.js handle events again 🤞.

I can work around it with the following code:

import { spinner } from '@clack/prompts';

const s = spinner();
s.start('Installing via npm');
// Do installation here
s.stop('Installed via npm');

+ process.on('SIGINT', () => {
+   process.exit(1);
+ });
cpreston321 commented 10 months ago

@mikenikles I think this is a separate issue! If you want to create a issue so we can track!

CC// @Mist3rBru

Mist3rBru commented 10 months ago

This is a separate issue, I can work on it later

tigawanna commented 9 months ago

any updates on this? trying to stop a process using ctrl + c is not working on Windows

Mist3rBru commented 9 months ago

@tigawanna If you are trying ctrl + c after an spinner, it has been tracked by #155 and will be solved on next release.

tigawanna commented 9 months ago

🙏

luisvinicius09 commented 4 months ago

Any updates? Or workaround?

luisvinicius09 commented 4 months ago

I made it work by just adding process.stdin.resume(); after emitting the keypress and setting raw mode. @Jwiggiff can you check if that's a solution, so we can close this issue?

I think this is not a clack's bug, I've tried similar code with inquirer and got the same results. By resuming the stdin everything works as intended.

Jwiggiff commented 4 months ago

Thank you @luisvinicius09 that worked for me!

luisvinicius09 commented 2 weeks ago

@cpreston321 I believe this one can be closed.