-
Notifications
You must be signed in to change notification settings - Fork 16
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
Improve Util.Pp
pretty-printers
#379
Conversation
LGTM, thanks! Should we do something similar for |
I’ve added an internal test for the pretty-printers, with variants for the truncation.
I don’t see what you have in mind, |
My bad, I was too fast reading the cut off code as only applying to strings and not bytes 🤦 |
The added tests look great BTW, and the expect outputs nicely answer the above question 😅 I guess having it print the final closing quote or square bracket like the OCaml toplevel will require some form of type-directed approach? utop # String.make 375 'a';;
- : string =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"... (* string length 375; truncated *)
utop # List.init 375 (fun _ -> [0]);;
- : int list list =
[[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0];
[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0];
[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0];
[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0];
[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0];
[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0];
[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0];
[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0];
[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0];
[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0];
[0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [0]; [...]; ...] This is just a thought - not meant as critique. I'm quite happy with this as a first version! |
😅
I think so. At the level where the truncating mechanism is located in that PR, it sees only the stream of bytes to output, without structure. I wondered whether the boxing or tagging mechanisms in formatters could be retargeted for that kind of purposes, but I didn’t find how. |
Reviewing the CI logs I realise (finally!) that (obviously, as it is one of the main goal of A simple way to fix pretty-printing with |
First of all, let me state that Code aside, too long outputs (strings, bytes, lists, ...) mangle the upside down Y-shape printed, which motivated the request for abbreviating print functions in #308 In CI logs, I'd rather skim over, e.g., an abbreviated string in an comprehendable Y-shape rather than see a long string in full detail. That suggests we should set the environment variable in the CI workflows. It would however be nice to be able to print the full string some way (locally and in the CI), say to create a standalone reproducer. That should however be possible by resetting the To keep things nice and without wrapped lines in the former scenario, setting the formatter margin to There may be cases I'm overlooking, say record types with lists in them that could warrant multi-line formatted strings. So far, such types haven't occurred in the interfaces we have tested 🤷 |
If the environment variable `MCTUTILS_TRUNCATE` is set to a integer greater than 0, `Util.Pp.to_show` will truncate strings that would have been larger than that with the message "... (truncated)" When `MCTUTILS_TRUNCATE` is less than the length of that message, it will be set to the length of that message - 1 Truncated strings will be of length `MCTUTILS_TRUNCATE`+1 Ensure that a global box is created when using `to_show`, as `Format` documentation says it is required
Bring `Util.Pp` in line with the code generated by `deriving show` by opening and closing boxes and placing break hints at the same positions
Add a generic pretty-printer for tuples, taking the tuple elements and pretty-printers as a list Add standard pretty-printers for tuples of size 2 to 10
CI summary for the latest run 64c1902
Neither of these are related to the PR, so I'll go ahead and merge |
Actually, it would be nice with a CHANGES entry to document changes in the user-facing Util.Pp module. |
Indeed! |
Yep, please do! 🙏 |
CI summary for 13d87f8
None of these are related to the PR, so I'll merge (and I mean it this time!) |
This PR brings a few features:
Format
boxes to provide the same formatting asderiving show
and abide byFormat
’s rule that all content should be output into some box,The possibility to truncate would address #308 if all pretty-printers in
STM
andLin
were always usingUtil.Pp
(this is #343).