yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

Maximum width on YAML::Flow layout

Open oblitum opened this issue 9 years ago • 4 comments
trafficstars

Hi. As of now I've followed the tutorial and read some docs. I have a question/feature-request:

  • Is there a way to limit width of emitter so that it automatically do line wrapping in Flow layout in case it gets too long?

For example, for the following YAML:

foo: [
    a, b, c,
    d, e, f
]

Emitting it through the API I get:

foo: [a, b, c, d, e, f]

The problem is when the sequence is quite long, I'd like to get some output like the former one, not too wide nor too tall.

oblitum avatar Oct 22 '16 21:10 oblitum

This is a very old bug, but I also think it would be great to have this feature. If I understand correctly, pyYaml supports setting a line width: https://dpinte.wordpress.com/2008/10/31/pyaml-dump-option/

davidzchen avatar Jun 20 '24 11:06 davidzchen

@jbeder Your thoughts on this? I have a similar case where I would like the lines to wrap after a certain length, similar to this example: https://github.com/zeldamods/oead/blob/master/test/byml/files/A-1_Dynamic.yml

It seems that both rapidyaml and pyaml have this behavior, but yaml-cpp does not support line wrapping.

davidzchen avatar Jun 22 '24 10:06 davidzchen

Sure, but I'm not sure how we'd get the output in the first example because it seems to know the entirety of the sequence, whereas the yaml-cpp API is streaming. But in principle yes.

jbeder avatar Jun 22 '24 12:06 jbeder

Makes sense. For my case, it would not necessarily have to be in the format of the first comment. Simple line wrapping would be fine for me. Something like:

- '!Parameters': {DropTable: Normal, InitMotionStatus: 0, IsEnemyLiftable: true, IsPlayerPut: false,
    SharpWeaponJudgeType: 0}

How difficult would such a change be? If you have some code pointers, I'd be happy to take a shot at it.

davidzchen avatar Jun 23 '24 02:06 davidzchen