77

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?

Duncan McGregor
  • 16,107
  • 10
  • 56
  • 106

5 Answers5

105

I am successfully using this plugin for Eclipse - ANSIConsole

Community
  • 1
  • 1
thegreendroid
  • 2,907
  • 4
  • 24
  • 39
  • @DuncanMcGregor Does the fact that you didn't switch the checkmark correctly suggest it did _not_ work? – Tobias Kienzler Nov 16 '12 at 09:16
  • No sorry, not using Eclipse ATM – Duncan McGregor Nov 16 '12 at 20:27
  • 1
    Excellent. Works like a charm and it's using the regular Eclipse console. Much easier than the accepted answer. – Damien Mar 31 '13 at 21:53
  • This doesn't seem to work out of the box with ncurses; the console understands some escape codes (such as changing the text colour) but others (including whatever it is ncurses prints with `initscr()` and `endwin()` get printed verbatim. I take it I need to set the `TERM` environment variable in the Run Configurations to something Ansi Console understands, but `xterm`, `ansi`, and a few others I've tried don't work. – Psychonaut Apr 07 '13 at 20:37
  • The reason this doesn't work with ncurses is mentioned on the website: "Since this plugin hooks into LineStyleListener, it cannot do anything other than changing the style of the current output. So no cursor movements, clear screen, etc." – krispy Feb 05 '14 at 20:52
  • It has annoying problems with multiline log entries (which have color code only on the first line): https://github.com/mihnita/ansi-econsole/issues/3 – Vsevolod Golovanov Sep 24 '14 at 11:06
  • this addon is a little bit slow- does any one have a faster alternative? – v.tralala May 10 '17 at 12:14
  • 1
    This doesn't seem to work with the jansi library. Add System.setProperty("jansi.passthrough", "true"); to make it work and override jansi's passthrough detection. – Eisenknurr Aug 26 '19 at 14:34
  • This does not seem to work in Eclipse 2020-12. Is there anything I have to do to enable ANSI support once installed? – Andrew S Mar 30 '21 at 16:15
28

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
sorin
  • 137,198
  • 150
  • 472
  • 707
Jim Hurne
  • 6,575
  • 3
  • 41
  • 42
  • 1
    Wow, I'd given up on this one. Thanks for dropping by! – Duncan McGregor Aug 16 '11 at 22:35
  • How can I direct the stdout calls `System.out.println()` to this Terminal, and not to the default Eclipse Console ? – Mark Jun 13 '13 at 23:50
  • 1
    @Mark: you might have better luck getting an answer if you ask in a new question (instead of asking in a comment). – Jim Hurne Jun 19 '13 at 09:03
  • @Mark, check the answer of ianinini. That works in default console. If not specified, the console font and color remains default; if escaped with ANSI, will colorize. – WesternGun Aug 31 '18 at 12:35
12

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.

ianinini
  • 425
  • 5
  • 12
4

You can use this plugin: http://code.google.com/p/elt/

See http://alexruiz.developerblogs.com/?p=2428

nafg
  • 2,059
  • 23
  • 22
  • This plugin allows the user to display a colour-capable terminal with a shell prompt. However, it doesn't seem to allow the user to direct their program output to this terminal. – Psychonaut Apr 07 '13 at 20:46
1

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.

Community
  • 1
  • 1
James Scriven
  • 6,719
  • 1
  • 28
  • 35