[proposal] add padding to Inspect.Opts

25 views
Skip to first unread message

Daniel Kukuła

unread,
Dec 1, 2022, 11:57:11 AM12/1/22
to elixir-lang-core
Currently we can set the width when inspecting - it would be useful to have also a padding option that accepts either an integer of empty strings or better a custom string so we can add `<br>` when pretty printing in html

José Valim

unread,
Dec 1, 2022, 12:03:54 PM12/1/22
to elixir-l...@googlegroups.com
Hi Daniel,

Can you please provide more information about the problem you are trying to solve? I have rendered inspected representations on HTML several times and I never needed extensions to the API. You should always be able to replace "\n" by either padding or "<br />" without concerns on the rendered output. So if you can explain what is not working or not possible, it would help move this forward.

Thanks!

On Thu, Dec 1, 2022 at 5:57 PM Daniel Kukuła <danie...@gmail.com> wrote:
Currently we can set the width when inspecting - it would be useful to have also a padding option that accepts either an integer of empty strings or better a custom string so we can add `<br>` when pretty printing in html

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/d55f03e0-20d0-4ca6-acdb-34ec97d510fan%40googlegroups.com.

Daniel Kukuła

unread,
Dec 1, 2022, 12:17:42 PM12/1/22
to elixir-lang-core
Recently I did a pr to hammox to use pretty printing in the inspected map.
Currently this is inspected as one line single line and it's a pain to look at when you have an mismatch in a struct.
The way hammox displays the errors is every nested error is padded 2 spaces deeper.
I had to split the inspected message and then join it with padding - I think that inspect should support it out of the box so we don't have to post process the generated message.
html is just an example where it's useful- every time I did inspect in a template I remember the same problem - the inspected structure is one long line.
https://github.com/msz/hammox/blob/a7afe45fd0f8ba79d06fde0a75458f76853572b3/lib/hammox/type_match_error.ex#L150

José Valim

unread,
Dec 1, 2022, 12:42:29 PM12/1/22
to elixir-l...@googlegroups.com
Right, given the behaviour can be achieved, I would rather rely on post-processing compared to adding more complexity to the codebase, unless there is a reason not to.

Note you could also perform a String.replace(string, "\n", "\n    ").

Daniel Kukuła

unread,
Dec 1, 2022, 12:55:03 PM12/1/22
to elixir-l...@googlegroups.com
Thanks for the suggestion.
--
Sincerely
Daniel Kukuła



You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/kieM-5VF72c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4JtLHbwGMgGEfSPDBwyzwgy-fwtrspgX64Wm4XQeRKgwg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages