Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected behavior when there is no output TTY #667

Open
nickwesselman opened this issue Aug 14, 2024 · 3 comments · May be fixed by #669
Open

Expected behavior when there is no output TTY #667

nickwesselman opened this issue Aug 14, 2024 · 3 comments · May be fixed by #669

Comments

@nickwesselman
Copy link

nickwesselman commented Aug 14, 2024

We have a command with long-running output in a <Static> which we would like our users to be able to pipe into a command like more or less. However ink does not seem to handle piped output / lack of TTY as there are ANSI escapes in the output. You also see re-renders for non-Static elements.

> npm run example examples/static | more

> [email protected] example
> NODE_NO_WARNINGS=1 node --loader ts-node/esm examples/static


Completed tests: 0
ESC[2KESC[1AESC[2KESC[1AESC[2KESC[G✔ Test #1

Completed tests: 1
ESC[2KESC[1AESC[2KESC[1AESC[2KESC[G✔ Test #2

Completed tests: 2
ESC[2KESC[1AESC[2KESC[1AESC[2KESC[G✔ Test #3

Completed tests: 3
ESC[2KESC[1AESC[2KESC[1AESC[2KESC[G✔ Test #4

Completed tests: 4
ESC[2KESC[1AESC[2KESC[1AESC[2KESC[G✔ Test #5

Completed tests: 5
ESC[2KESC[1AESC[2KESC[1AESC[2KESC[G✔ Test #6

Completed tests: 6
ESC[2KESC[1AESC[2KESC[1AESC[2KESC[G✔ Test #7

Completed tests: 7
ESC[2KESC[1AESC[2KESC[1AESC[2KESC[G✔ Test #8

Completed tests: 8
ESC[2KESC[1AESC[2KESC[1AESC[2KESC[G✔ Test #9

Completed tests: 9
ESC[2KESC[1AESC[2KESC[1AESC[2KESC[G✔ Test #10

Completed tests: 10

If you simulate a CI run via environment variable, it actually behaves exactly as I would expect:

> CI=1 npm run example examples/static | more

> [email protected] example
> NODE_NO_WARNINGS=1 node --loader ts-node/esm examples/static

✔ Test #1
✔ Test #2
✔ Test #3
✔ Test #4
✔ Test #5
✔ Test #6
✔ Test #7
✔ Test #8
✔ Test #9
✔ Test #10

Completed tests: 10

Shouldn't ink behave the same way for !process.stdout.isTTY as it would for isInCi? Is support for piping output not a common requirement in ink-based CLIs?

@nickwesselman
Copy link
Author

I'm thinking that all the isInCI behaviors in ink.tsx should be possible to enable or disable with a render option, but would default to on if isInCi || !process.stdout.isTTY.

@sindresorhus
Copy link
Collaborator

That makes sense to me 👍

@nickwesselman
Copy link
Author

Proposed a fix in #669

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants