Skip to content

[Bug] block() function leaves stdin in raw mode on Windows, breaking Ctrl+C signal handling #408

@christopher-buss

Description

@christopher-buss

Environment

  • OS: Windows 11 (MSYS_NT-10.0-26100)
  • Node Version: v22.20.0
  • Package: @clack/prompts
  • Package Version: v1.0.0-alpha.6

Describe the bug

After calling spinner.stop(), stdin remains in raw mode on Windows, preventing Ctrl+C from generating SIGINT signals. This breaks signal handling for any code that runs after the spinner stops.

The root cause is in the block() function's cleanup code, which intentionally skips restoring raw mode on Windows to prevent issue #176:

// From clack source - block() cleanup
if (input instanceof ReadStream && input.isTTY && !isWindows) {
    input.setRawMode(false);
}

This leaves stdin stuck in raw mode on Windows. In raw mode, Ctrl+C sends raw keypress data instead of generating SIGINT signals, so signal handlers never fire.

To Reproduce

Link to minimal reproduction:
https://stackblitz.com/edit/node-3wkqdznz?file=index.js,package.json

Steps to reproduce:

  1. Run the code above on Windows
  2. Wait for spinner to stop
  3. Press Ctrl+C
  4. Bug: Process hangs - SIGINT handler never fires because stdin is in raw mode

Expected behavior

Pressing Ctrl+C should:

  1. Generate a SIGINT signal
  2. Trigger the signal handler
  3. Print "✓ SIGINT received!"
  4. Exit the process

This works correctly on macOS/Linux but fails on Windows due to the !isWindows condition.

Additional Information

Workaround: Manually restore stdin after stopping the spinner:

spinner.stop("Done");
if (process.stdin.isTTY) {
    process.stdin.setRawMode(false);
}

If there's a Windows-specific reason to keep raw mode during spinner execution, I'm unsure of the reason. This is causing my issues on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Needs triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions