The default Console copy preserves the ANSI escapes
Outputs some text with ANSI escape sequences to the console For example with:
System.out.println("Hello \033[91mRED\033[m \033[101mRED\033[m world!");
The resulting console output is colored (red foreground / background), and the escape sequences (from \033 to m) are not visible.
But they are there (as LineStyleListener.lineGetStyle can't change the text, only add styles).
So the default copy command will take the text "as is", including the escape sequences.
Seeing those ANSI codes is only useful for debugging, and (probably) most users expect the copy to be WYSIWYG (so they don't expect to see the codes).
This is also the feedback I got (years ago) for the ANSI plugin (before it became part of Eclipse).
The plugin was doing something about it, but did it by "hijacking" the hotkey of the copy command. So Ctrl+C (Command+C on MacOS) did a copy without escape codes. But context menu - Copy did a copy with escapes.
See the thread during the integration into Eclipse: https://github.com/eclipse-platform/eclipse.platform.debug/issues/57
At the time I've tried replacing the Copy command properly, and also tried "tinkering" with the option menu. But I didn't manage to make things work well enough.
Any news on this? Also the html-support (still) seems to be broken in Eclipse 2023-03, despite https://github.com/eclipse-platform/eclipse.platform.debug/pull/86 being merged.
Just by chance I learned that Ctrl-Insert results in exactly the right thing, even having a proper html-variation in the clipboard. Wondering why this couldn't be the default for Ctrl-C ...
Yes and no :-(
I have a change that removes the escapes from the main "string flow", so searches (including regexp) and copy works fine.
But this breaks other areas.
For example there is an option in the console that shows the escapes. That is pretty handy for debugging (allows you to see the escapes when the result is not what you would expect).
It also breaks the "copy to clipboard with escapes", which some people use (including me at times). Handy to produce some output, then copy-paste it in a file that can later be cat to screen with attributes.
So I am not trying to fix those things.
@mihnita I get it can be pretty useful at times. Though I would argue: for many people it's probably not of interest - they just like some colored maven output and get annoyed when they want to copy some error output to github etc. ... So how about providing an option in the settings? Or at least add an informative text that explains the existence of the 'old-fashioned' copy-shortcut, that does the copy-text-only? Or switch the behavior of Ctrl-C and Ctrl-Insert? Just some thoughts as I noticed some people getting annoyed with it (plus myself), yet then giving up and saying: 'well, Eclipse is f***ed, better we make our organization switch to IntelliJ/VSCode/...'
I hear you.
So how about providing an option in the settings
These are already options (showing the escapes is an option, copy with / without escapes are different commands). So to have the options doing anything useful I first need to fix the broken stuff (which is what I was trying to do).
Right now the escapes are in text, so showing them, or putting them in the clipboard is zero effort. It just works.
But once I take them our of the main text flow I need to do some extra work to bring them back and merge them with the main text to show them or to put them in the clipboard.
What I can do is cleanup the preferences and remove the show escape option, remove the copy to clipboard with escapes, and submit things that way.
So that functionality will be gone, with the option to bring it back later.
But the escapes will be out of the text stream and the regexp / searches will work.
Thank you.
Actually I was not worried about finding/regex, just the copy/paste part. And as Ctrl-C and Ctrl-Insert already exist with different behavior I meant just that: I only learned about Ctrl-Insert doing a copy without escapes by some serious digging ... I don't expect people usually to be persistent on such an issue ;-) ...
But you're right, the finding/regex might be of interest. I think it might also relate to eclipse launchers, that start other launchers and wait for a certain output to stddev, right?
Thanks for your efforts! I really like the plugin and already did before it became part of the standard distribution. It also workes great with jansi.
Any chance you could just swap the Ctrl+C and Ctrl+Insert functionality? Chances are that most users are more interested in being able to do basic copy-paste than in being able to see/preserve the internal formatting. So things would be easy for the beginners, and more advanced users with advanced needs would still have the option to get the formatted version. Bonus points if you mention the command in the settings so that people don't need to find this thread to figure out it exists...
Any chance you could just swap the Ctrl+C and Ctrl+Insert functionality
At the time when I integrated the plugin into Eclipse there was some strong push-back against certain things that plugins are allowed to do, but Eclipse proper not.
One of them was hook and change the default handlers (including copy to clipboard).
Another example was my addition of "fancy icons" on the console toolbar (showing the current plugin status (enabled / disabled), and click to enable / disable).
The argument (and that makes sense) was that these are not good practices, and if a user does not like a plugin doing that they are free to uninstall the plugin. But they can't "uninstall" something that is in the core of Eclipse.
I am still considering moving the escapes out of the main stream of text. I think it would be a good move, and has a few other benefits.
That was not possible to do in a plugin, but now in Eclipse it is.
That would require some careful surgery, to not break anything. So I am a bit "skittish" about it... :-) But I would like to take a shot at it when I have some time.
In the meantime, if one is very bothered by the current behavior, one can change it, because it uses the standard commands mechanism. So you can bind any key combinations to the actions.
- Preferences > General > Keys
- Search for "ANSI Esc", and you will find 2 commands: "Copy Text With ANSI Escapes" and "Copy Text Without ANSI Escapes"
- Change the key binding to whatever you want.
I tried "Ctrl+C" for "Copy Text Without ANSI Escapes" and "Ctrl+Insert" for "Copy Text With ANSI Escapes" and it works
I don't know how to make this more discoverable. Maybe an option in General > Run/Debug > Console > ANSI Support