cdepillabout / pretty-simple

pretty-printer for Haskell data types that have a Show instance
https://hackage.haskell.org/package/pretty-simple
BSD 3-Clause "New" or "Revised" License
243 stars 29 forks source link

Indent whole expression #66

Closed georgefst closed 4 years ago

georgefst commented 4 years ago

I've often found myself wanting to indent a pretty-printed expression in it's entirety, e.g. when surrounding it by other text, as part of an error output.

Would you accept a PR that added an outputOptionsInitialIndent field (feel free to bikeshed the name) to OutputOptions?

I haven't yet looked at the code, but I imagine #25 would make this very easy, if it isn't already, as it would just amount to running with a non-zero in the initial state.

cdepillabout commented 4 years ago

@georgefst Yeah, this sounds good to me!

You'll have to look through the logic in src/Text/Pretty/Simple/Internal/OutputPrinter.hs to see if there is an easy place to indent every line.

Although, I also agree that doing this after #25 would probably be much easier, so if you are interested in implementing #25 first, please go ahead.

georgefst commented 4 years ago

I'm starting to think that using prettyprinter may be the cleaner solution, as discussed in that thread. So I think I'll experiment with that, if you approve.

Obviously that's a fairly sizeable change - how good is the test coverage?

cdepillabout commented 4 years ago

Yeah, I agree that using another package to help with outputting would be a good idea.

I don't really know the various choices, but it sounds like prettyprinter works well, so I'd be interested in seeing a solution using that (or even another library if you decide there is a better one).

how good is the test coverage?

The test coverage is okay-ish.

There are tests in src/Text/Pretty/Simple/Internal/OutputPrinter.hs that you saw, as well as a bunch of examples at the bottom of src/Text/Pretty/Simple.hs. Feel free to add more tests to make this task easier.

georgefst commented 4 years ago

prettyprinter is more or less the de facto standard (it's certainly very widely used), so I think I'll stick with that.

sjakobi commented 4 years ago

@georgefst BTW, if you find any difficulties in using prettyprinter, please do report them on the issue tracker. I'm quite keen on making it easier to adopt and easier to use.

georgefst commented 4 years ago

@sjakobi Will do.

FWIW, I've used it previously for a large project at work (and ended up extracting a library from that), and I've had no issues thus far.