-
Notifications
You must be signed in to change notification settings - Fork 25
Home
This Eclipse plugin interprets the ANSI escape sequences to color the console output.
This can be pretty handy when using something like jansi
.
But is also works if you output escape sequences directly from Java. Or from Perl, C++, or Groovy, or any other Eclipse hosted language.
The easiest way is from the Eclipse Marketplace. Help --> Eclipse Marketplace --> search for ANSI and install.
If you don’t have access to the Marketplace then you will have to add the install website “by hand”:
To install the plugin in Eclipse select Help -> Install New Software… and click “Add…” to add the following URL:
https://www.mihai-nita.net/eclipse
You can then select the site in the “Work with” list and continue the installation like with any other plugin.
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.
OK, so what CAN it do, you will ask.
From the “SGR (Select Graphic Rendition) parameters” table at https://en.wikipedia.org/wiki/ANSI_escape_code it can handle the following subset:
0 – Reset / Normal
1 – Bold: treated as intensity under Windows console, user option in this plugin)
2 – Intensity faint: “kind of” supported :-) It resets the intensity to normal.
3 – Italic: on (treated as inverse under Windows console, user option in this plugin)
4 – Underline
7 – Negative
8 – Conceal
9 – Crossed-out
21 – Double underline
22 – Bold off (normal intensity)
23 – Italic off
24 – Underline off
27 – Negative off
28 – Conceal off
29 – Crossed-out off
30-37 – Set text color
38 – Set xterm-256 text color
39 – Default text color
40 – 47 – Set background color
48 – Set xterm-256 background color
49 – Default background color
51 – Framed
54 – Framed off
90-97 – Set foreground color, high intensity
100-107 – Set background color, high intensity
The reasons for choosing these and not others are the limitations in the Eclipse console (for instance no blink :-), or limitation in the existing OS consoles (what’s the point in supporting something that can’t be used outside Eclipse).
But the final result is reasonable close to what you get in a real console in terms of colors (so no cursor movements, clear console, etc.)
For more functionality I might have to hook some more Eclipse events, or even to come up with my own console. But then I am not sure it can be used by applications in all kind of languages without code changes.
Considering that this started as a week-end toy project, it does not have such ambitions.
But if someone can point me to some simple methods that would allow me to implement that without tons of work, or even contribute code, I might take it there :-)
I have also tried to emulate Windows look (optional), with bold rendered as high intensity color, and italic as revere, and other attributes ignored.
It is debatable how close you can get to the right thing. Probably nobody knows what the ancient ANSI.SYS
supported. And at the time the DOS console did not support 256 colors.
Nowadays the Windows options that I am aware of are jansi,
ansicon, and ConEmu.
Between these three options, the support is uneven, and inconsistent.
In the non-Windows world there are also many terminals, also inconsistent, some of them with their own configurable options for how to treat various attributes.
So I don’t plan to try and emulate all the possible terminals.
But if you notice some glaring differences, let me know and I will try to do something about it.
If something does not seem to work, try running as simple "Hello world" test.
Java:
System.out.println("Hello \u001b[1;31mred\u001b[0m world!");
Or C:
printf("Hello \x1b[91mred\x1b[m world!");
Or C++:
cout << "Hello \x1b[91mred\x1b[m world!" << endl; // prints Hello red world!
The result should be something like this:
If you use jansi, it might look like the plugin does not work.
That is because jansi detects when the standard output is redirected and does not output the escape sequences anymore.
So try adding this to your code, before using jansi
: System.setProperty("jansi.passthrough", "true");
On GitHub, at https://github.com/mihnita/ansi-econsole.
To report issues: https://github.com/mihnita/ansi-econsole/issues
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.