mihnita / ansi-econsole

Eclipse plugin that understands ANSI escape sequences to color the Eclipse console output.
http://www.mihai-nita.net/java/
Other
90 stars 25 forks source link

Fix the bug that exception stack trace is not rendered properly. #31

Closed zhangzhx closed 6 years ago

zhangzhx commented 6 years ago

After enabled the plugin, when I have code like below, the console is not rendering the exception stack trace properly. This change fixes this.

System.out.println("Hello World");
System.out.println("I am a lucky guy");

System.out.println(4/0);

Screenshot for the console output

screen shot 2017-12-05 at 4 54 21 pm

mihnita commented 6 years ago

Sorry for the delay, I was very busy before the holidays... :-) Thank you for the interest, and for the pull request.


I am not sure I understand what is wrong with the current rendering?

I think that is as expected, no? "I am lucky guy" green, then the exception red, because it is the standard error.


And the proposed fix breaks the multi-line functionality. If you do something like

   System.out.println("\033[32mI am very");
   System.out.println("very");
   System.out.println("very");
   System.out.println("lucky guy\033[0m");

then the two "very" outputs should also be green.

But with returning as soon as there is no match it means that the current line gets no colors. And it should get the color from the previous line.

zhangzhx commented 6 years ago

Thanks for the reply. The Exception Stack Trace should look like this:

screen shot 2017-12-20 at 1 19 36 pm

I think the original code overrides the color palette of the Exception Stack Trace. It's hard to know I can click the target class line for the source code in the previous screenshot. I can update my PR to allow multiple lines match.

mihnita commented 6 years ago

Got it!

Has nothing to do with the fact that there is a colored string before or not. Just doing this as the only instruction is enough: int foo = 4 / 0;

I think this is caused by the fact that some output with a link already has color information associated, and my plugin does not account for that, assumes it all comes "clean slate"

This means that the current pull request is not a good fix, the right approach is to to "merge" the existing color info (that is used for the links) with the one generated by the plugin from ANSI escapes.

Thank you for discovering it, I have filed a bug :-)

mihnita commented 6 years ago

Here is the issue I have filed: https://github.com/mihnita/ansi-econsole/issues/32