Skip to content

Pipes don't work on Windows #420

Description

@edemaine

What happened?

On Windows, hunk does not accept keyboard input when fed data via stdin, such as a patch like so:

git diff | hunk patch -

Steps to reproduce

On Windows, in a repository with a working-tree diff:

npm install -g hunkdiff
git diff | hunk patch -

or from source:

git diff | bun run path\to\hunk\src\main.tsx -- patch -

Then try to interact with the TUI, e.g. arrow keys / scrolling / quit.

Expected behavior

Piped patch input should behave like normal interactive Hunk sessions on Windows (e.g. hunk diff). Instead, keys don't work.

Version

Current main / npm hunkdiff@0.15.1.

Solution explored

Hunk should be able to consume patch text from stdin while separately reading interactive input from the Windows console, ideally by opening:

fs.openSync("\\\\.\\CONIN$", "r+")

and wrapping that fd in new tty.ReadStream(fd). This is the Windows analog of opening /dev/tty as Hunk currently does, and it works on Node; see nodejs/node#63856

Unfortunately, this doesn't currently work in Bun: setRawMode fails. I wrote oven-sh/bun#32153 to fix it. If merged, I'll submit a PR to Hunk. Until then, even a correct Hunk-side CONIN$ implementation may still fail under Bun when enabling raw mode on the reopened non-stdin TTY.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions