-
Notifications
You must be signed in to change notification settings - Fork 49
Added indent with indicators to yaml-v12 #406
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
428c43f
Added indentWithIndicator option
5283f0a
Deprecate Printer(.Config) and introduce PrinterBuilder
9986864
Moved PrinterTest to use PrinterBuilder
a8ffb21
Added circe-yaml PrinterBuilder that uses circe-yaml-common.
527c1eb
Added file headers and ran scalafmt
c041ef9
Merge branch 'main' into add-indentWithIndicators
aheiska f65527c
Merge branch 'main' into add-indentWithIndicators
hamnis ff892af
Run scalafix
hamnis e4c4bb5
formatting
hamnis f6e918e
Make sure we have correct deprecation version
hamnis 6bdf8bd
Merge branch 'circe:main' into add-indentWithIndicators
aheiska dd4088a
Fixed issues found in review.
aheiska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
circe-yaml-v12/src/main/scala/io/circe/yaml/v12/PrinterBuilder.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright 2016 circe | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.circe.yaml.v12 | ||
|
||
import io.circe.yaml.common | ||
import io.circe.yaml.common.Printer._ | ||
import org.snakeyaml.engine.v2.api.DumpSettings | ||
import org.snakeyaml.engine.v2.common.{ NonPrintableStyle => SnakeNonPrintableStyle } | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
final case class PrinterBuilder private ( | ||
preserveOrder: Boolean = false, | ||
dropNullKeys: Boolean = false, | ||
indent: Int = 2, | ||
maxScalarWidth: Int = 80, | ||
splitLines: Boolean = true, | ||
indicatorIndent: Int = 0, | ||
indentWithIndicator: Boolean = false, | ||
tags: Map[String, String] = Map.empty, | ||
sequenceStyle: FlowStyle = FlowStyle.Block, | ||
mappingStyle: FlowStyle = FlowStyle.Block, | ||
stringStyle: StringStyle = StringStyle.Plain, | ||
lineBreak: LineBreak = LineBreak.Unix, | ||
explicitStart: Boolean = false, | ||
explicitEnd: Boolean = false, | ||
nonPrintableStyle: NonPrintableStyle = NonPrintableStyle.Escape | ||
) { | ||
def withPreserveOrder(preserveOrder: Boolean): PrinterBuilder = | ||
copy(preserveOrder = preserveOrder) | ||
|
||
def withDropNullKeys(dropNullKeys: Boolean): PrinterBuilder = | ||
copy(dropNullKeys = dropNullKeys) | ||
|
||
def withIndent(indent: Int): PrinterBuilder = | ||
copy(indent = indent) | ||
|
||
def withMaxScalarWidth(maxScalarWidth: Int): PrinterBuilder = | ||
copy(maxScalarWidth = maxScalarWidth) | ||
|
||
def withSplitLines(splitLines: Boolean): PrinterBuilder = | ||
copy(splitLines = splitLines) | ||
|
||
def withIndicatorIndent(indicatorIndent: Int): PrinterBuilder = | ||
copy(indicatorIndent = indicatorIndent) | ||
|
||
def withIndentWithIndicator(indentWithIndicator: Boolean): PrinterBuilder = | ||
copy(indentWithIndicator = indentWithIndicator) | ||
|
||
def withTags(tags: Map[String, String]): PrinterBuilder = | ||
copy(tags = tags) | ||
|
||
def withSequenceStyle(sequenceStyle: common.Printer.FlowStyle): PrinterBuilder = | ||
copy(sequenceStyle = sequenceStyle) | ||
|
||
def withMappingStyle(mappingStyle: common.Printer.FlowStyle): PrinterBuilder = | ||
copy(mappingStyle = mappingStyle) | ||
|
||
def withStringStyle(stringStyle: common.Printer.StringStyle): PrinterBuilder = | ||
copy(stringStyle = stringStyle) | ||
|
||
def withLineBreak(lineBreak: common.Printer.LineBreak): PrinterBuilder = | ||
copy(lineBreak = lineBreak) | ||
|
||
def withExplicitStart(explicitStart: Boolean): PrinterBuilder = | ||
copy(explicitStart = explicitStart) | ||
|
||
def withExplicitEnd(explicitEnd: Boolean): PrinterBuilder = | ||
copy(explicitEnd = explicitEnd) | ||
|
||
def withNonPrintableStyle(nonPrintableStyle: NonPrintableStyle): PrinterBuilder = | ||
copy(nonPrintableStyle = nonPrintableStyle) | ||
|
||
def build(): common.Printer = | ||
new PrinterImpl( | ||
stringStyle, | ||
preserveOrder, | ||
dropNullKeys, | ||
mappingStyle, | ||
sequenceStyle, | ||
DumpSettings | ||
.builder() | ||
.setIndent(indent) | ||
.setWidth(maxScalarWidth) | ||
.setSplitLines(splitLines) | ||
.setIndicatorIndent(indicatorIndent) | ||
.setIndentWithIndicator(indentWithIndicator) | ||
.setTagDirective(tags.asJava) | ||
.setDefaultScalarStyle(stringStyle.toScalarStyle) | ||
.setExplicitStart(explicitStart) | ||
.setExplicitEnd(explicitEnd) | ||
.setBestLineBreak { | ||
lineBreak match { | ||
case LineBreak.Unix => "\n" | ||
case LineBreak.Windows => "\r\n" | ||
case LineBreak.Mac => "\r" | ||
} | ||
} | ||
.setNonPrintableStyle { | ||
nonPrintableStyle match { | ||
case NonPrintableStyle.Binary => SnakeNonPrintableStyle.BINARY | ||
case NonPrintableStyle.Escape => SnakeNonPrintableStyle.ESCAPE | ||
} | ||
} | ||
.build() | ||
) | ||
} | ||
|
||
object PrinterBuilder { | ||
def apply(): PrinterBuilder = new PrinterBuilder() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.