0

How do you change the colors of Eclipse console using code? I know for red you can use System.err.print("test"); but I want a generalization for any color.

For example, I want a line of one color being blue, another line being magenta, and so on.

asp211
  • 11
  • 5
  • Eclipse Preferences > General > Appearance? – OneCricketeer Dec 11 '17 at 01:13
  • Do you mean you want to be able to write a program that prints multi-coloured text in the console (which can't be done, by the way); or do you just mean that you want to change the default black, red and green of the console to something different (which is easy)? – Dawood ibn Kareem Dec 11 '17 at 01:21
  • I see. Your edit answers my question. And what you want can't be done. Sorry. – Dawood ibn Kareem Dec 11 '17 at 01:22
  • @DawoodibnKareem _[...] And what you want can't be done_ [That's not entirely true](https://stackoverflow.com/a/5762502/1426227). – cassiomolin Dec 11 '17 at 01:39
  • @CassioMazzochiMolin Feel free to post that as an answer, and I will downvote it. OP asked about the standard Eclipse console, not some customised console. – Dawood ibn Kareem Dec 11 '17 at 01:43
  • This isn't really a duplicate since it's specific to Eclipse. I updated my answer with a link to a plugin that gives the Eclipse console support for color changing ANSI codes. – Sean O'Neil Dec 11 '17 at 01:45
  • @CassioMazzochiMolin, I agree with Sean. This isn't a duplicate. Would you consider re-opening it? – Dawood ibn Kareem Dec 11 '17 at 02:58

1 Answers1

0

Generally you cannot change console colors using Java code. Eclipse recognizes "System.err.print" as an error and displays a unique color for that, which is red by default. You can change various defaults in the preferences, but again, there is no Java code that allows you to pick a console output color.

Per Cassio's comment, there are ANSI escape codes to change colors but the console must support it. In order to support it in Eclipse, this plugin is available. https://github.com/mihnita/ansi-econsole

Sean O'Neil
  • 1,222
  • 12
  • 22
  • 1
    _[...] there is no Java code that allows you to pick a console output color._ [That's not entirely true](https://stackoverflow.com/a/5762502/1426227). – cassiomolin Dec 11 '17 at 01:38