pretty.rs icon indicating copy to clipboard operation
pretty.rs copied to clipboard

Handling text with newlines

Open TheNeikos opened this issue 2 years ago • 1 comments

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?

TheNeikos avatar May 02 '22 14:05 TheNeikos

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.

Marwes avatar May 03 '22 10:05 Marwes