An Eclipse console view that respects ANSI color codes?

The output from ScalaTest is colored to distinguish different states, but these end up as control codes and

[34m Annoying garbage

Is there any way to convince the Eclipse console to either respect or ignore these sequences, or to plug in a view that will?

43583 次浏览

How about redirecting your output to a file and then just "tail -f" it? Similar to this question: How can I make Eclipse output std:out to a standard windows console

Update: there are also some options listed at Colorize logs in eclipse console. Even if that doesn't work, it might be a starting point on how to swap out the standard console plugin.

The Target Management Terminal plugin for Eclipse understands ANSI escape characters, including color codes. I use it to run sbt with ScalaTest.

The original Target Management Terminal plugin was designed to access remote systems. However, if you are running on Linux, Mac, or Solaris but not Windows, you can use the Local Terminal plugin which adds the ability to attach directly to a local shell or program.

Installing the Local Terminal plugin automatically installs the Target Management Terminal, so you just need to install the local terminal:

Installing the Local Terminal plugin

  1. Select Help -> Install New Software... from the Eclipse menu
  2. Select the primary update site for you release of Eclipse (e.g., Ganymede, Helios, Indigo)
  3. Select General Tools -> Local Terminal
  4. Follow normal procedure to install the plugin (click next, accept license, restart eclipse, etc).

If you are running on a platform not supported by the Local Terminal plugin, you can still use Target Management Terminal with SSH or Telnet:

Installing the Target Management Terminal plugin

  1. Select Help -> Install New Software... from the Eclipse menu
  2. Select the primary update site for you release of Eclipse (e.g., Ganymede, Helios, Indigo)
  3. Select Mobile and Device Development -> Target Management Console
  4. Follow normal procedure to install the plugin (click next, accept license, restart eclipse, etc).

Using

  1. Select Window -> Show View -> Other from the Eclipse menu
  2. Select the Terminal -> Terminal view.
  3. Click the green Connect button in the view, and enter details to connect to your local system. If you installed the Local Terminal plugin, one of the options is "Local Program". By default, there is program defined for your local shell, but you can setup others. For example, I have an entry for sbt.

If you are more used to white-on-black, you might want to:

  1. Open Eclipse preferences
  2. Select Terminal
  3. Check Invert terminal colors

I am successfully using this plugin for Eclipse - ANSIConsole

This works brilliantly for me:

https://marketplace.eclipse.org/content/ansi-escape-console

Simply install it and it automatically modifies the behaviour of Eclipse's default console. (You can easily disable it with a button provided.)

I have used this for running code that outputs escape codes to modify the text colour. It behaves exactly as expected.

No need for an Eclipse plugin with Eclipse 4.25 (part of the Eclipse 2022-09 simultaneous release):

Support for ANSI escape codes in Console

Console interprets ANSI escape codes to produce styled output.

Supports 16 colors / 256 colors / true-colors for foreground and background, color palettes, and attributes like bold, italic, underline, invert, conceal, strike, crossed-out, framed:

Screenshot of a console with colored text -- https://www.eclipse.org/eclipse/news/4.25/images/ansi_sample.png

Only "CSI n m" (SGR, Select Graphic Rendition) control sequences are supported.
They set display attributes, but cannot be used to change the content of the output (erase actions, cursor positioning, scrolling).
Non-SGR sequences are not interpreted, but are recognized and hidden, so you will not see them.

This functionality is available for all the text output to the standard output or standard error.
It works for Java, C/C++, Perl, Python, shell, Groovy, Maven, any Eclipse supported language.

Preferences:

Screenshot of the ANSI support preferences dialog -- https://www.eclipse.org/eclipse/news/4.25/images/ansi_prefs.png