[code-reflection] RFR: OpWriter.ColoringOption proposal [v2]

Gary Frost gfrost at openjdk.org
Thu Sep 4 13:33:57 UTC 2025


On Thu, 4 Sep 2025 12:54:20 GMT, Adam Sotona <asotona at openjdk.org> wrote:

>> I propose OpWriter.ColoringOption, with NONE, ANSI, ANSI_HI and HTML  implementations:
>> - `OpWriter.toText(op, OpWriter.ColoringOption.ANSI))` will color the op with ANSI codes for terminal debug print (white background)
>> - `OpWriter.toText(op, OpWriter.ColoringOption.ANSI_HI))` will color the op with ANSI codes for terminal debug print (black background)
>> - `OpWriter.toText(op, OpWriter.ColoringOption.HTML))` will render the op with colors when dropped into an html `pre` block.
>> 
>> ANSI coloring sample:
>> <img width="989" height="746" alt="ansi-coloring" src="https://github.com/user-attachments/assets/2025bcbe-6c6c-48ab-8ed5-67ff88b47fe6" />
>> 
>> ANSI_HI coloring sample:
>> <img width="1267" height="566" alt="ansi-hi-coloring" src="https://github.com/user-attachments/assets/cd45838c-25b5-4980-9392-2b6ccf29e90b" />
>> 
>> 
>> HTML coloring sample:
>> <img width="914" height="657" alt="html-coloring" src="https://github.com/user-attachments/assets/77f62787-68c1-4b12-b16d-e7a526570ad3" />
>
> Adam Sotona has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Added OpWriter.ColoringOption.ANSI_HI

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.

-------------

PR Comment: https://git.openjdk.org/babylon/pull/546#issuecomment-3253745139


More information about the babylon-dev mailing list