gradle / gradle

Adaptable, fast automation for all

Home Page:https://gradle.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ability to determine state of the console

rjbell4 opened this issue · comments

Gradle internally knows whether or not the client is connected to a TTY, and (when the console has a default value of auto) determines whether to use a rich or plain console. This information can be useful to tasks, but it is not available, even (as far as I can tell) via internal calls or "sneaky methods" (like looking in /proc at the parent process), as the tasks execute in the Gradle daemon, separate from the client process.

Expected Behavior

An API available to tasks can report either whether a plain or rich console is being used (preferred), or whether or not stdout on the client is a TTY (second choice).

Current Behavior

This information is not available.

Context

I want to invoked a process in a task, and would like the invocation of this process to reflect whether the console is "rich", or not. For example, imagine a task that executes a script that has it's own --plain or --ansi arguments. That script cannot determine anything with a useful default using isatty(). The best thing would be to continue the same style of output that Gradle already determined was appropriate.

What happens if you force the tool you're invoking to use its "rich" output and Gradle's running with --console=plain? Is the output mixed?

@big-guy The idea here is that if Gradle determined the console should be plain (either because the user explicitly requested it, or because it was auto and Gradle determined that plain was necessary/appropriate), but then the tool is specifically told to use it's equivalent of "rich" content, then yes -- Gradle output will be plain, but the tool will output ANSI sequences, etc. This could undesirably put ANSI escape codes into log files, etc.

But that's essentially what we are doing to handle it right now -- invoke the tool explicitly to use rich output by default, and provide a separate toggle (project property, etc.) to change how the tool (or any other such tool) is invoked. Obviously, having a toggle for Gradle itself and a toggle for sub-tools is undesirable; it would be preferable to just make the invocation of the tools "match" Gradle. But to enable that, we need to be able to determine the style of the Gradle output programmatically.

commented

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

commented

This issue has been automatically closed due to inactivity. If you can reproduce this on a recent version of Gradle or if you have a good use case for this feature, please feel free to reopen the issue with steps to reproduce, a quick explanation of your use case or a high-quality pull request.