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

TerminalDetection not detecting IntelliJ #67

Open
bkahlert opened this issue Jul 20, 2022 · 6 comments
Open

TerminalDetection not detecting IntelliJ #67

bkahlert opened this issue Jul 20, 2022 · 6 comments

Comments

@bkahlert
Copy link

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 mac ManagementFactory.getRuntimeMXBean() returns the following elements

0 = "-Dorg.gradle.internal.worker.tmpdir=/Users/bkahlert/Development/com.bkahlert/kommons/build/tmp/jvmTest/work"
1 = "-Dorg.gradle.native=false"
2 = "-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=127.0.0.1:56426"
3 = "-javaagent:/Users/bkahlert/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core-jvm/1.6.1/97fd74ccf54a863d221956ffcd21835e168e2aaa/kotlinx-coroutines-core-jvm-1.6.1.jar"
4 = "--add-opens=java.base/java.util=ALL-UNNAMED"
5 = "--add-opens=java.base/java.lang=ALL-UNNAMED"
6 = "-Xms128m"
7 = "-Xmx512m"
8 = "-Dfile.encoding=UTF-8"
9 = "-Duser.country=US"
10 = "-Duser.language=en"
11 = "-Duser.variant"
12 = "-ea"

System.getProperty("sun.java.command") reports "worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 61'"

My environment reported by System.getenv() does neither contain IDEA_INITIAL_DIRECTORY, __INTELLIJ_COMMAND_HISTFILE__ nor TERMINAL_EMULATOR.

The following environment properties might help you:

...
"JAVA_MAIN_CLASS_56145" -> "worker.org.gradle.process.internal.worker.GradleWorkerMain"
"TOOLBOX_VERSION" -> "1.25.12424"
"__CFBundleIdentifier" -> "com.jetbrains.intellij"
"SHELL" -> "/bin/zsh"
"__CF_USER_TEXT_ENCODING" -> "0x40E34E6:0x0:0x0"
@ajalt
Copy link
Owner

ajalt commented Jul 21, 2022

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?

@sschuberth
Copy link
Contributor

sschuberth commented Jul 31, 2023

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.

@ajalt
Copy link
Owner

ajalt commented Jul 31, 2023

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.

@joseluisgs
Copy link

joseluisgs commented Oct 18, 2023

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

@sschuberth
Copy link
Contributor

Maybe the whole issue will get resolved with https://blog.jetbrains.com/idea/2024/02/the-new-terminal-beta-is-now-in-jetbrains-ides/?

@robstoll
Copy link
Contributor

robstoll commented Aug 4, 2024

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.

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