Package niceyaml combines the powers of go-yaml, bubbletea, and more.
It enables friendly and predictable handling of YAML-compatible documents in your CLI or TUI applications, and includes:
Sourcestyle overlay and annotation system- Pretty
Printerwith themes - Rich
Errordisplay using the above systems - Source
Revisions for file lineage and diffs - String
Finderfor load-once, search-many scenarios - Extended
EncoderandDecoderwrappers - JSON schema
generatorandvalidator - Bubble
yamlviewportfor Bubble Tea - Generic building blocks for your own bubbles
We use a parse-once, style-once approach. This means your users get a snappy UI, and you get a simple API. There's no need to employ multiple lexers, or perform any ANSI manipulation!
We also provide a consistent positioning system used throughout niceyaml. It enables each cell to be individually addressed, without any complexity being introduced by the specific display mode (e.g. diffs, slices).
go get go.jacobcolvin.com/niceyaml@latestPackage niceyaml adds a few abstractions on top of go-yaml:
Line- Tokens for a single line of YAML contentLines- Collection ofLines representing one or more YAML documentsSource- ManagesLineswhile abstracting away go-yaml lexer/parser details
Most use cases will only need to interact with Source. It satisfies most interfaces accepted by other niceyaml utilities.
These abstractions enable straightforward iteration over arbitrary lines of tokens from one or more YAML documents, while maintaining the original token details from the lexer. It cleanly solves common problems introduced by multi-line and/or overlapping tokens in diffs, partial rendering, and/or search.
flowchart LR
A["Input"]
subgraph Source
B["Lexer"] --> C["Parser"]
end
A --> Source
C --> D["Decoder"]
D --> E["Struct"]
See cmd/nyaml for a complete Bubble Tea application that loads, pages, searches, diffs, and validates YAML documents.



