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

Adam Sotona asotona at openjdk.org
Thu Sep 4 13:41:51 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

Yes, I was also thinking to expose the internal `BiFunction<Class<? extends CodeItem>, String, String>`.
However then I realized that the colorings should be concrete and simple to enable.
Maybe even affect the default `op.toText()` by a system property (similar to Maven `-Dstyle.color=(auto|always|never)`).

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

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


More information about the babylon-dev mailing list