bombshell-dev / clack

Effortlessly build beautiful command-line apps

Home Page:https://clack.cc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Can't handle keypresses after clack session

Jwiggiff opened this issue · comments

Environment

  • OS: Windows 10
  • Node Version: v18.16.1
  • Package: @clack/prompts
  • Package Version: ^0.6.3

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:

  • Use prompts to make a select menu
  • Try to handle keypresses manually afterwards

Expected behavior
Manual key handling works after prompts is done

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

If not please re-open this issue.

Thanks!

@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

commented

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);
+ });

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

CC// @Mist3rBru

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

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

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

Any updates? Or workaround?

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.

Thank you @luisvinicius09 that worked for me!

@cpreston321 I believe this one can be closed.