-
Notifications
You must be signed in to change notification settings - Fork 29
OpWriter.ColoringOption proposal #546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Welcome back asotona! A progress list of the required criteria for merging this PR into |
@asotona This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 10 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
I like the idea of making OpWriter more flexible and feel this will be useful tooling. I have suggested changes in this API for a while ;) I personally think this solution is too concrete, and we should offer a 'colorize' iface (BiFunction(Sttring,Tag, String) which we can pass to OpWriter.toText(). The default implementation of this iBiFunction would just return the String passed to it. OpWriter would then call this colorizer with a 'tag' enum/type (identifier, const, attribute, SSAid) and a String to be colorised, and the Colorizer/BiFunction gets to return a suitable colorised version ANSI/CSI/HTML/.... whatever which gets written to the PrintWriter. |
Yes, I was also thinking to expose the internal |
ANSI coloring is triggered by jdk.incubator.code.extern.OpWriter.COLOR property
Based on the offline discussion I would like to split this effort. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internal property is good, avoiding any API changes.
src/jdk.incubator.code/share/classes/jdk/incubator/code/extern/OpWriter.java
Outdated
Show resolved
Hide resolved
src/jdk.incubator.code/share/classes/jdk/incubator/code/extern/OpWriter.java
Outdated
Show resolved
Hide resolved
As I mentioned in slack. My problem here that that , if we have code which generates text from OpWriter buried in a lib call that you are unaware of, and you add this property on the command line (because you want to colorize some output from your call) everyone now needs to defecnd their code against these CSI/ANSI sequences. Specifically HAT was forced to reparse the output from OpWriter to apply its formmatting/tooling, this code is definately not expecting to see CSI/ANSI escape sequences in the output from OpWriter. I am in general favor of a solution, but the caller of OpWriter needs direct control of formatting, it should not be based on a global property IMHO. |
I see the problem. Technically it should be easy for |
It's really hard to get agreement in this area of writing and reading (the larger elephant in the room is the lack of specification for the grammar, there are higher priority areas to focus on). At this point i think it best we do nothing in the incubator module and instead focus on external tooling, like in hat but perhaps moved out to a separate project. |
@@ -186,6 +186,7 @@ public static Op fromStringOfJavaCodeModel(String in) { | |||
} | |||
|
|||
static List<Op> parse(OpFactory opFactory, TypeElementFactory typeFactory, String in) { | |||
in = in.replaceAll("\\033\\[\\d+m", ""); // remove ANSI coloring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cute hack, but it makes me uncomfortable.
I propose
OpWriter
enables simple ANSI coloring based onjdk.incubator.code.extern.OpWriter.COLOR
system property.ANSI coloring sample:

Progress
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/babylon.git pull/546/head:pull/546
$ git checkout pull/546
Update a local copy of the PR:
$ git checkout pull/546
$ git pull https://git.openjdk.org/babylon.git pull/546/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 546
View PR using the GUI difftool:
$ git pr show -t 546
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/babylon/pull/546.diff
Using Webrev
Link to Webrev Comment