Skip to content
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

Option to disable indentation #120

Closed
W4RH4WK opened this issue Oct 17, 2021 · 3 comments
Closed

Option to disable indentation #120

W4RH4WK opened this issue Oct 17, 2021 · 3 comments
Assignees
Labels
feature New feature or enhancement request implemented in v3 Fixes + features which were implemented in v3 release.

Comments

@W4RH4WK
Copy link

W4RH4WK commented Oct 17, 2021

Is your feature request related to a problem? Please describe.
I'd like to have TOML output with sub-tables not getting indented. It's not really a problem, just a personal preference.

Describe the solution you'd like
A flag for the formatter: allow_indentation, defaults to true.
Or, if the flags property of the formatter defaults to no flags set, disallow_indentation.

Additional context
Instead of this:

[Display]
displayName = '\\.\DISPLAY1'
fpsLimit = 100
vsync = true
windowMode = 'Windowed'

    [Display.mode]
    height = 1080
    refreshRate = 60
    width = 1920

[Graphics]
anisotropicFiltering = 'Medium'
antiAliasing = 'Off'

I'd like to have this:

[Display]
displayName = '\\.\DISPLAY1'
fpsLimit = 100
vsync = true
windowMode = 'Windowed'

[Display.mode]
height = 1080
refreshRate = 60
width = 1920

[Graphics]
anisotropicFiltering = 'Medium'
antiAliasing = 'Off'
@W4RH4WK W4RH4WK added the feature New feature or enhancement request label Oct 17, 2021
@marzer
Copy link
Owner

marzer commented Oct 18, 2021

Ah this is a good suggestion, and would be trivial to implement. I'll try to make time to implement this (and a few other small QoL fixes) at some point soon.

@marzer marzer added the v3 label Oct 25, 2021
marzer added a commit that referenced this issue Oct 27, 2021
also:
- minor refactoring (esp. GNU attributes)
- added documentation about formatters being free to ignore flags where necessary
@marzer
Copy link
Owner

marzer commented Oct 27, 2021

@W4RH4WK I've pushed an implementation of this to the v3 branch. There are two new additions to toml::format_flags:

  • indent_sub_tables: enables the indenting of sub-tables (for TOML formatter) or sub-objects (JSON formatter)
  • indent_array_elements enables the indenting of array elements when an array is long enough to require multiple lines

Both are enabled by default as part of the 'default' flag set for each formatter (since that was the existing behaviour), but you can achieve what you want by specifically overriding indent_sub_tables:

std::cout << default_formatter{ tbl, default_formatter::default_flags & ~format_flags::indent_sub_tables };

I won't merge v3 into master for a while yet since there's more work to be done before I cook a new release, but I welcome you to try it before then.

@marzer marzer added implemented in v3 Fixes + features which were implemented in v3 release. and removed v3 labels Nov 6, 2021
@W4RH4WK
Copy link
Author

W4RH4WK commented Dec 11, 2021

Sorry for taking my time with this. Just got around to trying it out. The flag works as expected. Thanks.

@marzer marzer closed this as completed in 18dfcf2 Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement request implemented in v3 Fixes + features which were implemented in v3 release.
Projects
None yet
Development

No branches or pull requests

2 participants