oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
72.43k stars 2.6k forks source link

Ink (CLI framework) not working properly #6862

Open DaniGuardiola opened 9 months ago

DaniGuardiola commented 9 months ago

What version of Bun is running?

1.0.7+b0393fba6200d8573f3433fb0af258a0e33ac157

What platform is your computer?

Microsoft Windows NT 10.0.22621.0 x64 (WSL: Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64)

What steps can reproduce the bug?

Create a simple Ink program that uses useInput. Run with bun.

What is the expected behavior?

Program responds to input.

What do you see instead?

Program does not respond to input.

Additional information

No response

DaniGuardiola commented 7 months ago

This bug was fixed by https://github.com/oven-sh/bun/pull/7650 👍

luiz290788 commented 6 months ago

Is this working? I was trying to run the use-input example from the ink repo and I couldn't make it to work with 1.0.23

DaniGuardiola commented 6 months ago

@luiz290788 in my case, I used (my own CLI) to test it: bunx classy-ink

It didn't work when I filed this issue, but now it does, at least for me. Feel free to try it yourself and let me know if inputs work for you.

luiz290788 commented 6 months ago

It is not working with the example in the repo. I will open another issue. I believe the problem is related to useApp.

orlandoxu commented 2 months ago

Not working

baublet commented 2 months ago

Can confirm, this doesn't seem to be working:

import React from "react";
import { render, Text, useApp, useInput } from "ink";

function Minimal() {
  const { exit } = useApp();
  useInput((input) => {
    if (input === "q") {
      exit();
    }
  });
  return React.createElement(Text, { color: "dim" }, ["This is a test; ctrl+c or q to exit"]);
}

render(React.createElement(Minimal));

process.on("exit", () => {
  const terminal = process.stderr.isTTY
    ? process.stderr
    : process.stdout.isTTY
      ? process.stdout
      : undefined;
  terminal?.write("\u001B[?25h");
});

Works fine in Node, never accepts input in Bun (pkill -f bun in another terminal to kill it)

DaniGuardiola commented 2 months ago

Re-opening since other people seem to still be running into this bug.

slavaGanzin commented 2 months ago

Bun doesn't call process.stdin.resume() And that is why app automatically exits and useIntput is not working.

@DaniGuardiola @baublet please, confirm that this works for you:

import React from "react";
import { render, Text, useApp, useInput } from "ink";

//you need this
process.stdin.resume()

function Minimal() {
  const { exit } = useApp();
  useInput((input) => {
    if (input === "q") {
      exit();
    }
  });
  return React.createElement(Text, { color: "dim" }, ["This is a test; ctrl+c or q to exit"]);
}

render(React.createElement(Minimal));

process.on("exit", () => {
  const terminal = process.stderr.isTTY
    ? process.stderr
    : process.stdout.isTTY
      ? process.stdout
      : undefined;
  terminal?.write("\u001B[?25h");
});
kevbot-git commented 1 month ago

@slavaGanzin thanks, I just tried this with Bun v1.1.14, and while the program waits for input, pressing q doesn't quit, as it does on node with ts-node. The ctrl + c functionality works, just not the q 😃

Bun doesn't call process.stdin.resume() And that is why app automatically exits and useIntput is not working.

@DaniGuardiola @baublet please, confirm that this works for you:

import React from "react";
import { render, Text, useApp, useInput } from "ink";

//you need this
process.stdin.resume()

function Minimal() {
  const { exit } = useApp();
  useInput((input) => {
    if (input === "q") {
      exit();
    }
  });
  return React.createElement(Text, { color: "dim" }, ["This is a test; ctrl+c or q to exit"]);
}

render(React.createElement(Minimal));

process.on("exit", () => {
  const terminal = process.stderr.isTTY
    ? process.stderr
    : process.stdout.isTTY
      ? process.stdout
      : undefined;
  terminal?.write("\u001B[?25h");
});
rutexd commented 2 weeks ago

idk if its related to this issue but looks like https://github.com/vadimdemedes/ink-text-input doesnt work aswell: it just exists the process. Bun 1.1.20, platform: windows. Looks like works only with process.stdin.resume() and you have to press ctrl-c two times to exit