From a3a9b42423282de0ed2702da206bd5c23808d233 Mon Sep 17 00:00:00 2001 From: Andrei Dragomir Date: Tue, 11 Dec 2018 11:42:32 +0200 Subject: [PATCH] Fixes https://github.com/go-yaml/yaml/issues/166 - ability to disable multi line string outputs --- encode.go | 4 ++++ yaml.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/encode.go b/encode.go index 0ee738e1..69355ec6 100644 --- a/encode.go +++ b/encode.go @@ -388,3 +388,7 @@ func (e *encoder) emitScalar(value, anchor, tag string, style yaml_scalar_style_ e.must(yaml_scalar_event_initialize(&e.event, []byte(anchor), []byte(tag), []byte(value), implicit, implicit, style)) e.emit() } + +func (e *encoder) setWidth(width int) { + yaml_emitter_set_width(&e.emitter, width) +} diff --git a/yaml.go b/yaml.go index de85aa4c..81c0d283 100644 --- a/yaml.go +++ b/yaml.go @@ -220,6 +220,13 @@ func NewEncoder(w io.Writer) *Encoder { } } +// SetLineWidth sets the preferred line width. +// To disable long line breaks set width lower than zero. +// By default, line width is set to 80. +func (e *Encoder) SetLineWidth(width int) { + e.encoder.setWidth(width) +} + // Encode writes the YAML encoding of v to the stream. // If multiple items are encoded to the stream, the // second and subsequent document will be preceded