-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PrintOptions for pretty printer. #100
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good change! We're almost there, I have only couple comments
src/Toml/Printer.hs
Outdated
prettyTables :: Int -> Text -> PrefixMap TOML -> Text | ||
prettyTables i pref = Text.concat . map prettyTable . HashMap.elems | ||
prettyTables :: PrintOptions -> Int -> Text -> PrefixMap TOML -> Text | ||
prettyTables options i pref = Text.concat . map prettyTable . HashMap.elems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it's a good idea to apply order
here as well. I think if you specify shouldSort
, you should sort table names as well.
src/Toml/Printer.hs
Outdated
{- | Default printing options. -} | ||
defaultOptions :: PrintOptions | ||
defaultOptions = PrintOptions True 2 | ||
|
||
-- Tab is equal to 2 spaces now. | ||
tab :: Int -> Text | ||
tab n = Text.cons '\n' (Text.replicate (2*n) " ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should also patch this function and replace 2 * n
with n
. As I understand correctly, the tab
function will be given numbers 0, 2, 4, 6, 8, ...
or 0, 4, 8, 12, ...
(depending on the indentation size) and previously it took numbers 0, 1, 2, 3, ...
. So instead of multiplying sequent natural numbers by indentation we can just add indent to the nextI
(as you already did) but also remove multiplier from the tab
function
The CI error is really weird and I don't quite understand, why it happens... Requires further investigation. Also, could you please update the CHANGELOG.md? |
CI is fixed now! See the comment in the other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactoring! There's only one bug in the current implementation.
Also, could you please update the CHANGELOG.md with the short description of your changes?
After that, I think, this PR can be merged 👍
-- Returns an indentation prefix | ||
tabWith :: PrintOptions -> Int -> Text | ||
tabWith options n = | ||
Text.cons '\n' (Text.replicate (n * indent options) " ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n
argument is redundant here and there's no need to multiply by n
. In the code you assign nextI
variable (which is responsible for indentation) to the value i + indent options
and you pass options
and i
to the tab
function. So, for example, if default indentation is 4
then layers will have the following indents:
- Nested 0:
indent = 4
,n = 0
=> tab is 0 spaces - Nested 1:
indent = 4
,n = 4
=> tab is 16 spaces - Nested 2:
indent = 4
,n = 8
=> tab is 32 spaces - and so on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I thought about it, but forgot to drop + indent options
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now n
means only a level of indentation (as it was before)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great addition to the library! Thank you very much, @astynax ! ❤️
Closes #11