Open bkahlert opened 2 years ago
Until IntelliJ is consistent about setting an environment variable, it's probably not possible to detect it in all cases. If you know of any envvar etc. that we can use, I'm happy to add it.
Does that __CFBundleIdentifier
value change if you invoke your program from gradle on the command line, or via java -jar
?
For the record, in IntelliJ IDEA 2023.2 I'm getting colored output with Mordant in the Run
tab. However, the terminal's width does not seem to be detected correctly (TerminalInfo
says it's 79), as my grid is truncated.
I suspect it's not possible to detect terminal size in IntelliJ's run console. On Windows at least, GetConsoleScreenBufferInfo fails. Even powershell itself can't detect anything.
I have a problem when I try to create a fat jar, no problem with IntellI console when I use a run. But when a create a fat jar, I use a java -jar, mordant crashes
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Library
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
at com.github.ajalt.mordant.internal.jna.JnaWin32MppImpls.<init>(JnaWin32MppImpls.kt:77)
at com.github.ajalt.mordant.internal.MppImplKt.<clinit>(MppImpl.kt:107)
at com.github.ajalt.mordant.terminal.TerminalDetection.isJediTerm(TerminalDetection.kt:160)
at com.github.ajalt.mordant.terminal.TerminalDetection.isIntellijRunActionConsole(TerminalDetection.kt:196)
at com.github.ajalt.mordant.terminal.TerminalDetection.detectTerminal(TerminalDetection.kt:16)
at com.github.ajalt.mordant.terminal.StdoutTerminalInterface.<init>(StdoutTerminalInterface.kt:17)
at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:56)
at com.github.ajalt.mordant.terminal.Terminal.<init>(Terminal.kt:45)
at MainKt.<clinit>(Main.kt:14)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Library
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
It is a problem with JNA, you need to include it to execute as a jar https://mvnrepository.com/artifact/net.java.dev.jna/jna/5.13.0
No problem with 2.0.0-beta9
Maybe the whole issue will get resolved with https://blog.jetbrains.com/idea/2024/02/the-new-terminal-beta-is-now-in-jetbrains-ides/?
on Unix like Systems it could work to see if the _
env variable contains idea
, most likely also not that reliable but better than nothing IMO.
The TerminalDetection computes
AnsiLevel.NONE
although I'm running my unit tests inside of IntelliJ (Build #IU-221.6008.13, built on July 19, 2022).The
runningInIdeaJavaAgent
method does not match. On my macManagementFactory.getRuntimeMXBean()
returns the following elementsSystem.getProperty("sun.java.command")
reports "worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 61'"My environment reported by
System.getenv()
does neither containIDEA_INITIAL_DIRECTORY
,__INTELLIJ_COMMAND_HISTFILE__
norTERMINAL_EMULATOR
.The following environment properties might help you: