bombshell-dev / clack

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

fix(@clack/core): keyboard input not working after await in spinner #182

Closed Mist3rBru closed 4 months ago

Mist3rBru commented 6 months ago

Fix #176

Description

The issue occurred on Windows, when the await line between the spinner start and stop was present, causing the second following prompt to be unresponsive to key inputs (e.g., arrow keys or Ctrl-C), except for the [Enter] key. Additionally, this resulted in the duplication of the first option.

Solution

The solution is identify when it is running on Windows and do not change terminal's mode

if (input.isTTY && !isWindows) input.setRawMode(false);

Tested Environment:

OS: Windows, Ubuntu Node Version: v18.17.1 Package: @clack/prompts Package Version: v0.7.0

Snippet to Reproduce

const sp = p.spinner();
sp.start("start");
await setTimeout(2000);
sp.stop("stop");

const y = await p.confirm({
  message: "Test anyway?",
});

const x = await p.multiselect({
  message: "test",
  options: [
    { value: "a", label: "A", hint: "hint A" },
    { value: "b", label: "B", hint: "hint B" },
    { value: "c", label: "C", hint: "hint C" },
  ],
  required: false,
});
changeset-bot[bot] commented 6 months ago

🦋 Changeset detected

Latest commit: a04e4189411cae685c460064bc329e4439845d43

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | -------------- | ----- | | @clack/core | Patch | | @clack/prompts | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

lucas-zimerman commented 6 months ago

that indeed fixes the issues, I just wonder why it only affects the second call

lucas-zimerman commented 6 months ago

We actually don't need input.setRawMode The thing is that clear here is being used for two flows (exiting the program if ctrl-c is pressed and clearing the line) instead of one (clearing the line).

On linux, SIGINT should be triggered so we can hook to it (I'll have to check it)

I'll add my suggestions on separated lines so that it can be marked as solved if implemented or discuss specifics parts of the suggestion.

Lms24 commented 5 months ago

Hey @natemoo-re friendly bump: any chance this PR could get reviewed and merged in?

rorry121 commented 2 days ago

Any news?When will a new version be released? @natemoo-re