Skip to content

Implement more robust isTTY check#63

Merged
jorgebucaran merged 2 commits into
jorgebucaran:mainfrom
kibertoad:fix/isatty
Sep 7, 2021
Merged

Implement more robust isTTY check#63
jorgebucaran merged 2 commits into
jorgebucaran:mainfrom
kibertoad:fix/isatty

Conversation

@kibertoad

Copy link
Copy Markdown
Collaborator

@kibertoad

Copy link
Copy Markdown
Collaborator Author

@jorgebucaran What's up with GitHub actions? I see there is a CI flow defined, but it doesn't seem to be running.

@mcollina

mcollina commented Sep 5, 2021

Copy link
Copy Markdown

I can confirm this fixes the compatibility problems we have for pino transport

@jorgebucaran

Copy link
Copy Markdown
Owner

Wow, thanks! So, is this Node's canonical way to detect if you are in a pipe? Other than not being available inside worker_threads, are there any disadvantages to process.stdout.isTTY? Curious.

@jorgebucaran jorgebucaran added the enhancement New feature or request label Sep 5, 2021
@jorgebucaran

Copy link
Copy Markdown
Owner

@jorgebucaran What's up with GitHub actions? I see there is a CI flow defined, but it doesn't seem to be running.

It was configured to run against push only. It's fixed now. 🙆‍♂️

@kibertoad

Copy link
Copy Markdown
Collaborator Author

@jorgebucaran This discussion might be useful: nodejs/node#28386

@mcollina

mcollina commented Sep 7, 2021

Copy link
Copy Markdown

@jorgebucaran is there an ETA for a release that would ship this?

Comment thread index.js Outdated
@@ -1,12 +1,13 @@
const tty = require('tty');

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colorette is an ES module, so this should be changed to use import.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will that be compatible with current dual publishing of CJS and ES versions? do you autoreplace?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, looks like the time to upgrade that script has finally come! I can take care of that after we merge this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jorgebucaran

Copy link
Copy Markdown
Owner

Thanks! I'll merge here, update the script and publish a new minor version shortly.

@jorgebucaran jorgebucaran merged commit 9b6f41e into jorgebucaran:main Sep 7, 2021
@jorgebucaran

Copy link
Copy Markdown
Owner

Released as 1.4.0.

@kibertoad kibertoad deleted the fix/isatty branch September 7, 2021 18:52
@jorgebucaran

Copy link
Copy Markdown
Owner

@mcollina @kibertoad Is there any reason to check if tty is defined before using tty.isatty()? Should be defined, no?

import * as tty from "tty"
 ...
const isCompatibleTerminal =
  tty && tty.isatty(1) && env.TERM && env.TERM !== "dumb"

@kibertoad

Copy link
Copy Markdown
Collaborator Author

@jorgebucaran It's a node-specific thing. There were prior bug reports from people using colorette outside of Node, I wanted to safeguard against that from the get go.

@jorgebucaran

Copy link
Copy Markdown
Owner

Gotcha, thanks. I still feel that this should be handled by the user's bundler / preprocessor (#64 (comment)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants