Crates.io | pretty-xmlish |
lib.rs | pretty-xmlish |
version | 0.1.13 |
source | src |
created_at | 2023-01-23 21:09:19.435416 |
updated_at | 2023-06-24 01:43:01.179241 |
description | Pretty print XML-ish data with unicode art |
homepage | |
repository | |
max_upload_size | |
id | 766210 |
size | 31,187 |
feature: phil-wadler authors:
This RFC proposes a new API for pretty-printing pseudo "structures". The purpose of the API is to supersede the current implementation of SQL explain, and maybe more.
pretty
crate.
This gives us spaces to simplify the design and implementation.I tried to use the pretty
crate to implement SQL explain, but it turned out to be limited in many ways:
pretty
is a pure (Config, Doc) -> String
algorithm with potential configurations.
I believe that we essentially need to upgrade this from a reader monad to a state monad.However, the standard Wadler-style "algebraic" pretty printing API is well-designed and can be extended to support the features we desire.
I saw a screenshot by @xxchan
on a private Slack channel that shows the SQL explain output of databend's system,
which inspired me to write this RFC.
These contents are subject to future changes.
XmlNode
and Pretty
for pretty printing dataPretty
are hereafter called "pretty" or "pretties".XmlNode
represent XML-like data that has a name, a list of attributes, and a list of children nodes.Variants of Pretty
:
Record
that brutally pretty-prints an XML-like data.
Array
that brutally pretty-prints an array-like data.
Text
that pretty-prints a string.
PrettyConfig
for pretty printing configurationIt contains indentation, preferred width, etc.
LinedBuffer
for actually writing the stringIt contains a mutable reference to a String
, and a PrettyConfig
.
It understands the intended width (precomputed by PrettyConfig::interesting_*
),
and will try to fill an incomplete line with spaces when asked so.
Pretty::ol_len_*(&self) -> usize
Pretty::ol_build_string_*(&self, build: &mut String)
PrettyConfig::interesting_*
LinedBuffer::line_*
(private)
|
and the ending |
and the indentations.
It will try to fill the intermediate spaces and lines, but not the surrounding.PrettyConfig::horizon
+
at the ends and -
in the middle.PrettyConfig::ascii
interesting
to predict the output width, and then generate the beautiful output, using pure ASCII style.PrettyConfig::unicode
interesting
to predict the output width, and then generate the beautiful output, using Unicode table-making characters.BTreeMap
to associate vector to preserve insertion order