pretty.rs
pretty.rs copied to clipboard
Handling text with newlines
I would like to use pretty
to print text that comes from users. The problem is that it will contain new lines. What would be the preferred way of using it here? Should I simply break up the string myself on newlines and add each seperately with Doc::text
?
You can use https://docs.rs/pretty/0.11.3/pretty/trait.DocAllocator.html#method.reflow if you are fine with treating newlines the same as any whitespace. Otherwise you will need to break it up yourself as Doc::text
will treat newlines the same as any other character so it tends to mess up the width calculation.