turbo icon indicating copy to clipboard operation
turbo copied to clipboard

Support colored output from original CLI

Open charkour opened this issue 2 years ago • 15 comments

Describe the feature you'd like to request

Show original CLI colors in the output.

Describe the solution you'd like

I would like to be able to have a --colors flag when running turbo to enable colors of the CLI output, including the output from the sub packages/apps. turbo would likely set the environment variable FORCE_COLOR=1 before running commands.

Describe alternatives you've considered

Manually setting the monorepo's environment variable to FORCE_COLOR=1. This enables color when packages, like Next.js, use the npm package chalk

charkour avatar Dec 13 '21 03:12 charkour

I would be willing to make a PR for this if applicable. Thanks!

charkour avatar Dec 13 '21 03:12 charkour

Go for it.

jaredpalmer avatar Dec 13 '21 03:12 jaredpalmer

Start here: https://github.com/vercel/turborepo/blob/155c5c3451f1e5ef26034fc9eeb99b40bb98b838/cli/internal/run/run.go#L716

and around here is where to set FORCE_COLOR: https://github.com/vercel/turborepo/blob/155c5c3451f1e5ef26034fc9eeb99b40bb98b838/cli/internal/run/run.go#L487

jaredpalmer avatar Dec 13 '21 03:12 jaredpalmer

Thanks! I'll work on it tomorrow night.

charkour avatar Dec 13 '21 03:12 charkour

@charkour Are you in the Discord? If not, join us!

jaredpalmer avatar Dec 13 '21 14:12 jaredpalmer

Yes! Thank you. With a different profile picture.

charkour avatar Dec 13 '21 14:12 charkour

I had a little time to try implementing this and found that the FORCE_COLOR environment variable needs to be set in the working directory where the command is executed (for example docs). Setting it after line 487 doesn't correctly force the color.

I'll work on this more tomorrow. Let me know if you have any ideas. Go is a new language to me.

charkour avatar Dec 14 '21 02:12 charkour

I am making good progress on this.

charkour avatar Dec 16 '21 11:12 charkour

Is there any update on this? 🎅🎄🎁

paul-vd avatar Jan 15 '22 15:01 paul-vd

If you're using node, you can set FORCE_COLOR=1 in your environment variables. The PR hasn't been reviewed.

charkour avatar Jan 15 '22 18:01 charkour

@charkour Yea that's what I'm currently using, but it seems like quite a dirty solution, For example, if you have 10 packages with each of them having roughly ~4 commands image This would mean that you need to make at least 40 changes to enable colors.

I think it would be much better to use --colors, or considering the comment in your PR, the flag could be something like --node-colors instead, and eventually a unified --colors flag depending on the decisions. but yea the feature in your PR would be most welcoming. That would avoid having to set the FORCE_COLOR=1 in ~40 different places 😅

paul-vd avatar Feb 22 '22 17:02 paul-vd

@charkour Has this been implemented yet?

Seems like a neat thing to have.

tigerabrodi avatar Jul 28 '22 04:07 tigerabrodi

Hey @narutosstudent, I don't believe this has been implemented yet. My original PR was closed because I had incorrectly made this assumption about node environments being the only use case for turborepo.

For a workaround, I'd recommend using FORCE_COLOR=1 in your environment variables if you are using a node environment.

charkour avatar Jul 28 '22 12:07 charkour

I'm having problems in my local terminal (i'm using tilix on linux) to show colors automatically, i think the TTY detection is not working as it should. Other utils are showing colors without any problem.

@jaredpalmer could be a problem with this line ?

https://github.com/sebaplaza/turborepo/blob/main/cli/internal/ui/ui.go#L17-L18

Edit: I tested the go-isatty output and the tty is being detected, the problem is that isTTY is not being used as a method to activate colors.

sebaplaza avatar Sep 15 '22 08:09 sebaplaza

@charkour Yea that's what I'm currently using, but it seems like quite a dirty solution, For example, if you have 10 packages with each of them having roughly ~4 commands image This would mean that you need to make at least 40 changes to enable colors.

I think it would be much better to use --colors, or considering the comment in your PR, the flag could be something like --node-colors instead, and eventually a unified --colors flag depending on the decisions. but yea the feature in your PR would be most welcoming. That would avoid having to set the FORCE_COLOR=1 in ~40 different places 😅

FYI, you don't have to put FORCE_COLOR into every package, only before the turbo run command in your top level package.json. For example, this worked for me to get colors working with vitest:

{
  "scripts": {
    "test": "FORCE_COLOR=1 turbo run test"
  },
}

And the actual package.json for the package only includes

{
  "scripts": {
    "test": "vitest"
  },
}

janvennemann avatar Sep 23 '22 08:09 janvennemann

just another piece of info here that this also seems to apply to running turbo itself which is not a great look.

aka: turbo typecheck:all (which is "typecheck:all": "turbo run typecheck --continue" in root package.json) works but is completely white which makes it nearly impossible to discern the output from different packages.

scamden avatar Jan 07 '23 01:01 scamden

no spinners, colors, and other terminal progress animation/indicators.

I wanted to cite this from the closed-as-duplicate #2251 issue. Can we change the title of this to Support output from original CLI (colors, spinner, etc)? I occasionally search for spinner and hope to more quickly find this one to check on progress. (I have also subscribed this time 😉.)

FORCE_COLOR=1 does not seem to help with spinners or other animation.

connorjs avatar Mar 09 '23 00:03 connorjs

Any updates on this?

dbousamra avatar May 03 '23 03:05 dbousamra

Just want to voice my support for adding this. It is extremely important for dev ergonomics and accessibility.

finnatsea avatar May 10 '23 16:05 finnatsea

Just want to voice my support for adding this. It is extremely important for dev ergonomics and accessibility.

@finnatsea just add FORCE_COLOR=1 as an env variable and you'll have that! :)

ZeldOcarina avatar May 25 '23 12:05 ZeldOcarina

FORCE_COLOR=1 Is not working for me, and based on the responses here since the first mention of that solution, it is also not working for others. My guess if folks recommending it are not clear on what is being requested. This request is for the original cli output from the task to maintain it's colors. This usually will mean the child process' need to be run in a TTY, and my educated guess (I read some of the code here) is that this env var does nothing to effect how the process is spawned. So unless whatever tools are run in the task process also respect FORCE_COLOR then they will not think they should display colors.

If this was a JS package, we could use node-pty and even the most rudimentary tools would likely follow suite and display colors. Since this is not JS, I have no idea if there are any good libraries for this. But I would like to say that until this feature is added, the UX of running turbo in anything but CI is significantly worse than it could be.

An example:

https://github.com/tapjs/tap-mocha-reporter/blob/f4b1acea21f723a68ea5be2ec321a1a0412c0cea/lib/reporters/base.js#L5

This package for parsing tap output uses TAP_COLORS as it's override, but will respect if the stdin/out is TTY. If I manually set this in my package.json script, turbo will maintain the colors with or without FORCE_COLOR being set. But that means that EVERY single consumer needs to know what options are available in each tool to force colors, and it means the normal detection libraries need to do is overridden. This can cause issues in CI systems which don't understand colors (jenkins used to be like this).

wesleytodd avatar May 27 '23 18:05 wesleytodd

Not sure it seems a very complex explanation but it is working for me: image

ZeldOcarina avatar Jun 05 '23 13:06 ZeldOcarina

Why isn't this the default? I know that some maintainers consider this a low on the list nice-to-have, but I could not disagree more. This is so pronounced that nx even have a section about how much this sucks and is a reason to choose nx instead...

I am sure there is some hidden complexity around this, but thats not a reason to abandon this for almost 2 years.

If it is required and some maintainer is willing, I will gladly 1:1 to understand how to implement it, and make a PR

datner avatar Jun 06 '23 11:06 datner

Not sure it seems a very complex explanation but it is working for me: image

@ZeldOcarina This is because whatever is running in your task is doing one of two things:

  1. ignoring that it is not a TTY and ouputing ansi color escape codes anyway (which is generally not considered good)
  2. respecting FORCE_COLOR to turn them on. which is fine, but not all tools do this.

What my comment above was about is having turbo trick the task process into thinking it is running in a TTY shell which would set the correct defaults for almost all tools in the node.js ecosystem.

wesleytodd avatar Jun 06 '23 14:06 wesleytodd

After waiting over a year, we're moving to nx almost solely because of this. We even overlooked the failing daemon issues on Windows (ended up just disabling it). But eventually it was determined that colorized lint/format/test/build/* output is too critical for development and none of the workarounds attempted/suggested were satisfactory.

billyzkid avatar Jul 06 '23 21:07 billyzkid

@billyzkid In case this update helps you, I think I was able to get colors out of all the tools I was using by wrapping the call to turbo in a pty via node-pty. I think one of the reasons this is confusing folks is that there are many layers at work. I know nothing of your setup, but I think that no one in this thread has (including myself) posted a reduced test case for where turbo specifically is breaking the colors. And seeing as I was able to get colors in my tool which parses the turbo log output and transforms it into a web ui with colors in the logs, I am pretty sure at this point turbo is not the cause but is only making the reason harder to debug.

wesleytodd avatar Jul 06 '23 23:07 wesleytodd

image image Using concurrently, colors from concurrently won't show in terminal when starting from turbo

Adrien5902 avatar Oct 08 '23 21:10 Adrien5902

@Adrien5902 concurrently is almost certainly doing this wrong, but did you try passing --no-no-color? Yargs boolean args should not include no- because it will do it itself. I took a quick look at what it is doing with with that option and under the hood it passes FORCE_COLOR to the tools, but that env var is not universal, hence the problem with tools like this not using a PTY.

Either way, I don't think your issue with with turbo.

wesleytodd avatar Oct 09 '23 15:10 wesleytodd

@wesleytodd thanks for answering, you must be right, I don't know why vite has colors while concurrently doesn't but it does not matter the issue is probably with concurrently. I resumed working on this old project which used concurrently and I moved to a monorepo to have server side and client side split. But it'll be even better if I split electron and vite in two different packages anyway. So I won't have the need for concurrently anymore.

Adrien5902 avatar Oct 11 '23 16:10 Adrien5902

An update for those following this issue: We're aiming to land this feature in Turborepo 1.12!

anthonyshew avatar Jan 17 '24 06:01 anthonyshew