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

dumb mode: don't silently enable colors when parent process contains "idea" in it's path #814

Closed
unkarjedy opened this issue Jan 9, 2023 · 2 comments
Milestone

Comments

@unkarjedy
Copy link

(I don't have isolated reproduction steps, please let me know if you need them.
Originally the issue was found to be a root cause of https://youtrack.jetbrains.com/issue/SCL-20177)

Create JLine in dumb mode by passing TERM=dumb environment variables.
Launch the process from some java installed at some location idea in its path.
E.g. your system user could be named "Eideard".

Expected result
It's expected that there are no colors in dumb mode

Actual result
Colors are printed in dump mode

This logic is located in org.jline.terminal.TerminalBuilder#doBuild:

...
if (terminal == null && (dumb == null || dumb)) {
    // forced colored dumb terminal
    Boolean color = this.color;
    if (color == null) {
        ...
        // detect Intellij Idea
        if (!color) {
            String command = getParentProcessCommand();
            color = command != null && command.contains("idea");
        }
        ...

I don't have the full background for the change, it was originally introduced in this commit with description "experiment" which isn't very descriptive.

Such implicit behavior seems quite unexpected.
If someone wants to enable colors even in dumb mode there should be some explicit argument for that.
If somewhere in IDEA the colors are indeed needed with dumb JLine, then the argument could be passed explicitly.

@gnodet
Copy link
Member

gnodet commented Mar 3, 2023

The idea is that jline can autodetect when run inside IDEA, which does support ansi colours. Do you have a problem because the detection was wrong, or because you're running inside IDEA but do not want the colour support to be detected, or because the detection indicates it's running in IDEA but colours are not really supported in your use case ?
It's a heuristic, so it can be refined at will.

@gnodet gnodet added this to the 3.23.0 milestone Mar 3, 2023
@unkarjedy
Copy link
Author

@gnodet Thanks for the response.

The issue I faces is described in detail in this comment:
https://youtrack.jetbrains.com/issue/SCL-20177/Scala-3-REPL-prompt-scala-appears-only-after-the-first-line-is-submitted#focus=Comments-27-6766972.0-0

I would highlight 2 issues there:

  1. JLine implicitly enabled colors even when we explicitly put it in dump mode. No warnings, no logs, etc...
  2. It was very hard to debug the issue because in Dev/Debug IDEA I couldn't reproduce the issue due to this magic logic command.contains("idea");

Do you have a problem because the detection was wrong,

It was wrong for Dev IDEA where the command line doesn't contain "idea".
It contains "java.exe" with the last program argument "com.intellij.idea.Main"

or because you're running inside IDEA but do not want the colour support to be detected

This as well, because we used TERM=dumb but colors still were shown in non-dev IDEA.


Note that I fixed the original issue in IntelliJ IDEA Scala Plugin.
But such implicit logic complicates the process of understanding the system.
It's not mentioned anywhere in the docs (at least I couldn't find it).
The more such magic we have in various tools the harder our life will be (and when we speak of IDEA there are dozens if not hundreds of tools involved)
To me, this commit "experiment" was a quick patch which shouldn't have been to end up in the final version.
It would be more clear if IntelliJ IDEA explicitly passed the colors flag.

@segrey maybe you could also comment on that?

@gnodet gnodet closed this as completed in c571b14 Mar 8, 2023
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