ndmitchell / cmdargs

Haskell library for command line argument processing
Other
91 stars 12 forks source link

an attempt to fix #18 -- preserve line breaks in the help text during wrap #38

Closed ozgurakgun closed 8 years ago

ozgurakgun commented 8 years ago

I am not totally sure what wrap, wrap1, etc are supposed to do. I tried to guess my way, but I don't think this PR is correct as it currently stands. I am submitting it anyway in the hope to be useful.

It "works" correctly in isolation, but I am not sure if it fits with the rest of the code. Please let me know what wrap is supposed to do and I can have another look.

Some sample output, in isolation.

*System.Console.CmdArgs.Text> putStr $ unlines $ wrap 10 "this is a test"
this is a
test
*System.Console.CmdArgs.Text> putStr $ unlines $ wrap 10 "this is\na test"
this is
a test

Whereas with the current wrap both outputs would have been identical.

ndmitchell commented 8 years ago

Thanks for the pull request! I'm quite snowed under at the moment but will hope to take a look tonight or tomorrow.

ndmitchell commented 8 years ago

Thanks for the code. Looking at the problem, I've taken the first 2 lines of your commit (the bit adding concatMap and lines), and I think that actually solves the whole problem - I don't see any real impact in the changes to the rest?

For the rest, the split and combine implementations, I'm not sure I super understand what was there before, or your revised version - it's a relatively ugly problem in Haskell. Please let me know if I've missed some way in which yours is better? As it happens, I recently wrote an entire blog post on a function that is relatively similar to this, but for an entirely different purpose: http://neilmitchell.blogspot.co.uk/2016/01/a-simple-haskell-function.html

ozgurakgun commented 8 years ago

It is entirely possible for the rest of my changes to be zero impact. :)

Since I couldn't work out what split and combine did, I started by trying to reimplement those to something I understand better, then did the first-2-lines bit. I am glad the simpler fix works though.