mihnita / ansi-econsole

Eclipse plugin that understands ANSI escape sequences to color the Eclipse console output.
http://www.mihai-nita.net/java/
Other
90 stars 25 forks source link

Please export package mnita.ansiconsole.participants #6

Closed fmjrey closed 10 years ago

fmjrey commented 10 years ago

Hi there, Would you be able to export the package mnita.ansiconsole.participants in your plugin definition. This would allow me to reuse your stylelistener for other purposes. If you're curious, this is about making the REPL of the Clojure plugin be able to display ansi codes: I've pushed the changes I've made to CCW there: https://github.com/fmjrey/ccw/commits/ansi-console The CCW plugin script that reuse your listener is there: https://gist.github.com/fmjrey/9889500 It's still a bit experimental though... Cheers, François

mihnita commented 10 years ago

Hi François, Thank you for the interest. You can prepare a pull request.

I am just curious about how you intend to use this. That class does nothing special, I don't see how it can be used by a third party. And there are no promises of stability, it can break from "under you" at any time :-) Plus it makes you dependent on my plugin.

Can't you just output text with ansi escapes and let the plugin do the job? I don't think you need to "hook" into it in any way. Or is output from other plugins not captured?

Might also have another option: just copy the whole class, change the name, and make it your own. It is under an Apache 2.0 license, pretty liberal. That way you don't depend on my plugin to be installed. (although one might see conflicts if both classes start hooking the console :-)

Again, if you create a pull request I will (very-very likely) approve it. But I would like to understand :-)

Best regards, Mihai

fmjrey commented 10 years ago

Hi Mihail, In fact I thought a pull request for such a small change was a bit too much for a one liner automated by the plugin.xml eclipse editor. I can still make one if you prefer. Actually in my setup I'm letting your plugin do the job. The CCW plugin script I referenced above is a script run by eclipse that test if your plugin is present, and if so reuse your stylelistener (instantiate it as is) to apply it to the clojure REPL. I preferred to do it this way precisely for the reasons you mentioned, and if your plugin is not installed or if you make a breaking change the script will fail but it won't break anything else beyond the script, I'll just have some annoying error logs that will bring this to my attention. Let me know if you want a pull request, otherwise it's just adding the package mnita.ansiconsole.participants to the list of exported packages in the runtime tab of the plugin.xml editor. Thanks François

mihnita commented 10 years ago

Hmmm, so all you need is to detect if my plugin is installed? Because I really don't see how can you use my style listener. Sorry for insisting so much, I am not against (as long as you say "I don't mind if you break my stuff" :-) But I am trying to understand why (and how) you want to reuse the listener, maybe I learn something.

Cheers, Mihai

fmjrey commented 10 years ago

Yes I'm already able to detect the presence of your plugin. If present, I can only instantiate AnsiConsoleStyleListener if its package is exported. I already implemented the export in my environment. Asking you to export the package would certainly make it easier for other people to use my CCW script plugin (CCW=CounterClockWise, the eclipse plugin for developing in clojure), since they won't need to hack your plugin like I did. Below is a screenshot of what the Ansi Clojure REPL looks like.

ansi-repl-screenshot

As the screenshot shows, the result isn't perfect yet. The resulting contrast isn't easy for the eyes, probably because I'm using a dark theme, unless CCW does its own coloring. Those familiar with CCW will also see that code is no longer syntax-highlighted like it used to.

Regarding your hesitation and questions I think they are perfectly valid, even more so since what I'm talking about smells like a hack: a way to use your software in ways you did not intend. However another way to understand this use case is how your plugin could become a more generic service for supporting ansi codes in StyledText widgets, not just in the console.

I'm not very familiar with StyledText stuff, but it certainly means integrating someone else's style with the ansi style within the listener. From what I understand it seems more than one LineStyleListener can be added to a StyledText, so that may be the way to go. It would probably be simpler than creating some extensions points in your plugin.

In short your valid questions could be transformed into:

Perhaps a bit more than you expected but still nice to consider.

fmjrey commented 10 years ago

For the record here's the discussion on CCW google group that got this started: https://groups.google.com/d/msg/clojuredev-users/d3rXWdWTJAs/d59iUhBhCZoJ

paulvi commented 10 years ago

In fact I thought a pull request for such a small change was a bit too much for a one liner automated by the plugin.xml eclipse editor. I can still make one if you prefer.

@fmjrey Francois, with GitHub it is possible to edit online, without cloning to local PC. Could you point to relevant code at https://github.com/laurentpetit/ccw please

@mihnita That is actually great idea. It can be used for Node.js too.

fmjrey commented 10 years ago

@PaulVI: you mean the line to be changed in this project, right? In which case it's this: Add the following line Export-Package: mnita.ansiconsole.participants at the end of https://github.com/mihnita/ansi-econsole/blob/master/AnsiConsole/META-INF/MANIFEST.MF I'd be curious to know how to do what you're saying: editing without cloning and then make a pull request?

fmjrey commented 10 years ago

Well I just found that Edit button... so the pull request is there ;) Thanks Paul for the pointer. Hope I also answered your question.

paulvi commented 10 years ago

Welcome

paulvi commented 10 years ago

ref https://github.com/laurentpetit/ccw/pull/28

mihnita commented 10 years ago

Released a new version, with mnita.ansiconsole.participants exposed

How could ANSI Console be made more generic and be used not just for the console?

This seems like a bigger change, and I am not even sure ansi escapes are the best option. Thing is, for now at least, the plugin hooks into an event that passes a line and says "add styles to this thing" It means I cannot change the text (if you copy the colored text from the console and paste it in a text editor you will see that the escape sequences are there, but hidden) And cannot do anything outside the current line (so no cursor movement, screen erase, etc.) It is also the cause of bug https://github.com/mihnita/ansi-econsole/issues/3

How can it be friendlier with existing darker theme, or syntax highlighting?

The colors use the palette of the real OS, so you can't have it "friendlier" It looks like it would look in a real terminal. If that is too pale, then that's the way it will also be in Eclipse. If you want brighter colors, then use the "intense" colors.

Those are not supported in a consistent way across OSes though. It can be achieved by {esc}[1;31m (bold-red, displayed in Windows and some terminals as intense), or {esc}[91m (unt understood by Windows though). (and when I say Windows, I mean ansicon, as the Windows console does not understand ansi escapes at all). For Win you can also try alternate consoles (conemu, console2, or even bash under cywgin)

So, no portable way. But with this plugin, in Eclipse, {esc}[91m will do.

fmjrey commented 10 years ago

Thanks Mihai,

Regarding issue #3: what a painful bug! I'm surprised the Eclipse Console does not cache the styles as well, considering a console is mostly a read-only view. I would even consider that a bug in eclipse, thought about filing one? As you say I don't think such caching should your responsibility.

The CCW REPL augmented with your listener isn't affected by it. I'm not sure what makes the CCW REPL unaffected, problably some caching. In case you're curious here's the CCW REPL view code: https://github.com/laurentpetit/ccw/blob/master/ccw.core/src/java/ccw/repl/REPLView.java

Regarding being friendlier to theme and syntax coloring perhaps more insight/requirements will come from having your code being reused elsewhere than the console. As I said, I'm not so familiar with StyledText.

mihnita commented 10 years ago

"The CCW REPL augmented with your listener isn't affected by it." You need some special conditions to see it. The idea is to have a line that starts a color, it does not end it, then outputs enough lines to scroll the beginning out of view, before the final end (color reset). Not very common. A bit more common with a small windows, few lines.

mihnita commented 10 years ago

Regarding being friendlier to theme and syntax coloring perhaps more insight/requirements will come from having your code being reused elsewhere than the console.

I still don't think this is the best way to colorize StyledText. REPL need to produce some escape codes that have to be parsed afterwards...

What I would do is probably create an easy to use API, something like jansi, which in the belly does styling directly on the StyledText control, instead of going through a "narrow hook" In fact, might even imitate the jansi API 100%. That way once can call the same APIs and depending on the library used end up with native StyledText calls, or ansi escape sequences.

But that's my just my first gut feeling.

About coloring: you can try another palette. Some are lighter than others. If you can choose what colors to output, you can go with bright colors. Or anything that looks bright to you, from the 256 colors range.

But overall you are limited by what the escape sequences can represent. If it is "red" and "bright red", there is not much of a choice beyond that. The only option would be to customize the palette...

mihnita commented 10 years ago

Should we rather close this bug? And we can chat on this by email, or on the CCW list. :-)

fmjrey commented 10 years ago

Yes let's close it. If more needs to be said, can be elsewhere or a new issue somewhere. I can understand your point about ANSI codes not being the best way to colorize text in Eclipse. But isn't the whole point of your plugin to be compatible with command line tools that use colors for better output on text terminals? I guess this is the common point between console and repl: they display the output of a process that normally run standalone with a text terminal and not within eclipse. I don't think we need to use your plugin for other situations.

paulvi commented 10 years ago

considering a console is mostly a read-only view.

@fmjrey It is actually possible to type in console while the build or app is running (and letter search for the string). It is different experience

And we can chat on this by email, or on the CCW list.

It is better to have separate issue for separate question. I would not be following if you continue not on GitHub. But do as you consider is better.