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

Colour not being detected #1

Closed
sksamuel opened this issue Mar 10, 2019 · 14 comments
Closed

Colour not being detected #1

sksamuel opened this issue Mar 10, 2019 · 14 comments

Comments

@sksamuel
Copy link

Using intellij, just a simple function to output some colour.
JDK11, Intellij 2018.3, Mordant 1.2.0

image

image

@sksamuel
Copy link
Author

System.console() is returning null, but we know intellij can do colour as log4j etc will happily output in colour in intellij.

@ajalt
Copy link
Owner

ajalt commented Mar 10, 2019

Yeah, Java's terminal detection is shamefully bad. If you're writing a program where you know you'll always be used interactively, you can force color output: TermColors(TermColors.Level.TRUECOLOR).

For the IntelliJ case specifically, It looks like idea_rt.jar gets added to the classpath when running from within the IDE itself, so I think looking for that jar would be a reasonable heuristic.

There's also the possibility of using JNI to call the native isatty function for better detection, although I'm slightly hesitant to add native code to the project.

What do you think about any of those options?

@sksamuel
Copy link
Author

Either of the first two. Maybe update docs for the ability to override.
Kolor (another library) doesn't bother with detection as far I can see.
Rather than look for idea_rt.jar I'd be tempted to see if CommandLineWrapper is on the classpath as that's specifically the class that Intellij uses to launch processes.

@ajalt
Copy link
Owner

ajalt commented Mar 17, 2019

Ok, I just released version 1.2.1 which should improve the detection in the IntelliJ console.

It turned out that neither idea_rt.jar nor CommandLineWrapper were reliably added to the classpath. I ended up looking at the javaagent used to launch the JNI process and checking for IntelliJ's.

Let me know if that works, or if you have any ideas on better approaches. You can always still force a color option if you find that detection isn't reliable enough.

@ajalt ajalt closed this as completed Mar 17, 2019
@sksamuel
Copy link
Author

Detects it as None for me I'm afraid. Maybe it works on a Mac but not Linux?

@sksamuel
Copy link
Author

sksamuel commented Jun 15, 2019

These are the input args to the management bean on my machine.

0 = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=46407"
1 = "-Dfile.encoding=UTF-8"
2 = "-Duser.country=GB"
3 = "-Duser.language=en"
4 = "-Duser.variant"
5 = "-ea"

@ajalt ajalt reopened this Jun 15, 2019
@sksamuel
Copy link
Author

sksamuel commented Jun 15, 2019 via email

@sksamuel
Copy link
Author

sksamuel commented Jun 16, 2019 via email

@ajalt
Copy link
Owner

ajalt commented Jun 16, 2019

Yes, an IntelliJ gradle task is the same as running gradle from the command line. I'm pretty sure gradle wraps stdout, so isatty returns false. Even if we detect that we're running in gradle, the user can still redirect gradle's stdout, so always using colors inside gradle would be incorrect. Maybe you can configure your gradle task to set the envvar COLORTERM=truecolor, which will cause mordant to always use color?

I welcome other suggestions on how to improve the behavior.

@sksamuel
Copy link
Author

sksamuel commented Jun 16, 2019 via email

@ajalt
Copy link
Owner

ajalt commented Jun 17, 2019

Ok. I'll leave this issue open for now in case someone knows of a better solution.

@LoganDark
Copy link

LoganDark commented Sep 15, 2019

IntelliJ's run window has always been shoddy. I'm disappointed that only PyCharm has an actual terminal emulator. I mean come on, you gave PYTHON a terminal, but not Java, or C++?!

@elect86
Copy link

elect86 commented Feb 20, 2020

Looking for Idea compatibility, I found this issue..

@sksamuel I tried to clone this project itself and run the main under samples, it works flawless

am I missing something?

IntelliJ IDEA 2020.1 EAP (Ultimate Edition)
Build #IU-201.5616.10, built on February 19, 2020

@LordMZTE
Copy link

LordMZTE commented Aug 5, 2020

on the windows command line there's also no color and if it is forced then there's just garbage characters.

edit: it appears that colors in the windows console must be manually enabled using regedit. please refer to this issue on how to do that

edit 2: while this registry editing method linked above does allow colors, mordant will still think the terminal is incapable of colors and thus won't use colors if auto detection is used

@ajalt ajalt closed this as completed Nov 2, 2020
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

5 participants