haskell-boxes / boxes

A pretty-printing library for laying out text in two dimensions, using a simple box model.
Other
37 stars 13 forks source link

Alternative formatting without trailing spaces #32

Closed amigalemming closed 3 years ago

amigalemming commented 5 years ago

I have vertically stacked text boxes of differing widths. When rendered they are all right padded with white spaces. A single box of large width causes lots of padded small boxes. The padding allows additional line breaks in a terminal if it is too narrow. Although this behavior is correct it can be annoying. How about an alternative rendering function that emits only the spaces that are necessary for formatting? Maybe it should even be a rendering function that allows formatting options that can be extended in the future.

kindaro commented 5 years ago

Actually, is there any reason for these spaces to be there at all?

srghma commented 3 years ago

Actually, is there any reason for these spaces to be there at all?

agree, we had the same question https://github.com/cdepillabout/purescript-boxes/pull/4#issuecomment-776674950

I have proposed to remove them on render

render = unlines <<< map trimEnd <<< renderBox

https://github.com/cdepillabout/purescript-boxes/pull/4/files#diff-980b256e266644ec0180b0cdf4f0505390932b648d8c0674a1a0b13fbec284cbR368

https://github.com/haskell-boxes/boxes/blob/903c2c9a043dd985d1a95ee2e79613cf0d77f946/Text/PrettyPrint/Boxes.hs#L363


The reason is that it would give better diffs in tests

E.g.

You have a text file with golden/expected state

foo
barbar

but then boxes renders you the same, but with spaces appended

foo<3 spaces>
barbar

and diff fails

@byorgey @treeow