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

IntelliJ console is not detected from a code started via Gradle's JavaExec task #7

Closed
jonnyzzz opened this issue Oct 22, 2020 · 7 comments

Comments

@jonnyzzz
Copy link

I have a Java application with the library and start it from IntelliJ IDEA via a Gradle JavaExec task.
The console is not detected in that scenario.

The detector code actually fails on the line

if (!consoleAvailable()) return NONE

@jonnyzzz
Copy link
Author

The actual environment variables from the Gradle session under IntelliJ (committing obvious ones):

JAVA_MAIN_CLASS_27354=com.jonnyzzz.teamcity.rr.RViewMain
LANG=en_US.UTF-8
LESS=-R
LSCOLORS=Gxfxcxdxbxegedabagacad
OLDPWD=/
PAGER=less
SHELL=/bin/zsh
TERM=xterm
TOOLBOX_VERSION=1.18.7455
USER=jonnyzzz
VERSIONER_PYTHON_VERSION=2.7
XPC_FLAGS=0x0
XPC_SERVICE_NAME=com.jetbrains.intellij.29860.373ECF8D-4625-4FA3-B1D7-91E0EE789D61
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0

The TERM=xterm is actually set

@ajalt
Copy link
Owner

ajalt commented Oct 22, 2020

Checking System.console() != null is all we have access to on the JVM. If you know of a way to improve detection here outside of JNI, I'd love to hear it. But unfortunately, I'm not sure there's anything we can do.

If you know you're going to be running on an interactive terminal, you can force a given color level when creating your TermColors instance. For example, to always output truecolor:

TermColors(TermColors.Level.TRUECOLOR)

@jonnyzzz
Copy link
Author

jonnyzzz commented Oct 22, 2020 via email

@ajalt
Copy link
Owner

ajalt commented Oct 22, 2020

I don't think that's reliable. Ignoring System.console would result in a false-positive if the environment variable exists but stdout isn't interactive (e.g. you pipe the output of a command somewhere).

@jonnyzzz
Copy link
Author

I agree. It would be nice allow manually call the terminal mode detection without the console mode check. That could be a solution to my case, so I could call the detection and ignore the console mode check. Would that make sense?

@ajalt
Copy link
Owner

ajalt commented Jan 28, 2021

Yes, that seems like a good idea. I'll look into implementing the option to force interactivity while still detecting other terminal info.

@ajalt
Copy link
Owner

ajalt commented Feb 10, 2021

I implemented this suggestion in 2.0.0-alpha2: If you create your terminal with Terminal(interactive = true), it will skip the console check, but will still look at environment variables to determine ansi support.

@ajalt ajalt closed this as completed Feb 10, 2021
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

No branches or pull requests

2 participants