ron-rs/ron

How to properly format the file?

apoorv569 opened this issue · 2 comments

This this is my PrettyConfig,

        PrettyConfig::new()
            .depth_limit(2)
            .separate_tuple_members(true)
            .enumerate_arrays(true)
            .struct_names(true)

and my ron generated config looks like this,

ThemeConfig(
    enable_theming: false,
    waveform_config: WaveformConfig(
        color: Color32((254, 150, 71, 255)),
    ),
    widget_config: WidgetConfig(
        button: ButtonConfig(color: Color32((60, 60, 60, 255)), rounding: Rounding(nw: 2.0, ne: 2.0, sw: 2.0, se: 2.0), padding: Vec2(x: 4.0, y: 1.0)),
        text: TextConfig(color: Color32((140, 140, 140, 255)), warn_color: Color32((255, 143, 0, 255)), error_color: Color32((255, 0, 0, 255))),
        panel: PanelConfig(panel_bg_color: Color32((27, 27, 27, 255)), faint_bg_color: Color32((5, 5, 5, 0))),
        extreme_bg_color: Color32((10, 10, 10, 255)),
    ),
    widget_shape: WidgetShape(
        shape: Circle,
    ),
)

I want for each field to be on newline (indented) like the struct fields appear with rust syntax.

if I change depth to 4, its somewhat what I want,

ThemeConfig(
    enable_theming: false,
    waveform_config: WaveformConfig(
        color: Color32((
            254,
            150,
            71,
            255,
        )),
    ),
    widget_config: WidgetConfig(
        button: ButtonConfig(
            color: Color32((
                60,
                60,
                60,
                255,
            )),
            rounding: Rounding(
                nw: 2.0,
                ne: 2.0,
                sw: 2.0,
                se: 2.0,
            ),
            padding: Vec2(
                x: 4.0,
                y: 1.0,
            ),
        ),
        text: TextConfig(
            color: Color32((
                140,
                140,
                140,
                255,
            )),
            warn_color: Color32((
                255,
                143,
                0,
                255,
            )),
            error_color: Color32((
                255,
                0,
                0,
                255,
            )),
        ),
        panel: PanelConfig(
            panel_bg_color: Color32((
                27,
                27,
                27,
                255,
            )),
            faint_bg_color: Color32((
                5,
                5,
                5,
                0,
            )),
        ),
        extreme_bg_color: Color32((
            10,
            10,
            10,
            255,
        )),
    ),
    widget_shape: WidgetShape(
        shape: Circle,
    ),
)

but I don't want each arg to be on a newline.. I want something more like this,

ThemeConfig(
    enable_theming: false,
    waveform_config: WaveformConfig(
        color: Color32((254, 150, 71, 255,)),
    ),
    widget_config: WidgetConfig(
        button: ButtonConfig(
            color: Color32((60, 60, 60, 255,)),
            rounding: Rounding(nw: 2.0, ne: 2.0, sw: 2.0, se: 2.0,),
            padding: Vec2(x: 4.0, y: 1.0,),),
        text: TextConfig(
            color: Color32((140, 140, 140, 255,)),
            warn_color: Color32((255, 143, 0, 255,)),
            error_color: Color32((255, 0, 0, 255,)),
        ),
        panel: PanelConfig(
            panel_bg_color: Color32((27, 27, 27, 255,)),
            faint_bg_color: Color32((5, 5, 5, 0,)),
        ),
        extreme_bg_color: Color32((10, 10, 10, 255,)),
    ),
    widget_shape: WidgetShape(
        shape: Circle,
    ),
)

Also is it possible to add comments and newlines manually?

At the moment, the best you can achieve is (probably) to set your depth limit to 3 and to disable the separate_tuple_members option. Unfortunately, ron does not offer more precise control over the formatting.

While a magic wrapper type could be added that sets a custom depth limit for a subtree of the RON document, this would probably be too specific to RON (unless there is already such a type in a general crate that other formats support and for which RON could implement support).

At the moment, the best you can achieve is (probably) to set your depth limit to 3 and to disable the separate_tuple_members option. Unfortunately, ron does not offer more precise control over the formatting.

This works! Thanks!

While a magic wrapper type could be added that sets a custom depth limit for a subtree of the RON document, this would probably be too specific to RON (unless there is already such a type in a general crate that other formats support and for which RON could implement support).

That would be nice to have though!