ocaml-containers icon indicating copy to clipboard operation
ocaml-containers copied to clipboard

Ignore style in Containers_pp

Open grayswandyr opened this issue 1 year ago • 2 comments

Following up from this discussion on Discuss: I'd like to have a way to avoid outputting style formatting in some circumstances (e.g. it seems Utop doesn't like styles when using `#install_printer#).

Although it would be less efficient, I tend to think the separation between document building and document printing speaks for providing a conditional printing function, akin to CCFormat.fprintf_dyn_color. What do you think?

Regarding how to implement this, I'm not sure to understand exactly how printing works in Containers_pp but it seems that the idea would be to ignore the color/styles extension when in a Wrap constructor when printing...?

grayswandyr avatar Jul 29 '24 09:07 grayswandyr

It's a bit tricky as things are right now, because extensions are responsible for their own printing. So, the color extension is the only thing aware of how colors are printed. I'm not sure how to transmit the information between the call to Containers_pp.pp out doc and the internal calls to Term_color's extension pre and post callbacks (bottom of containers_pp.ml).

Maybe a simple option would be to have an optional disabled_ext:string list -> … parameter to the printing functions. This doesn't break existing code (optional) but it'd modify the printers in Pretty to just skip the Wrap constructor when the extension's name is in the disabled list. (We would only print the inner document as is). What do you think?

c-cube avatar Jul 29 '24 17:07 c-cube

I like that!

grayswandyr avatar Jul 30 '24 07:07 grayswandyr