- All Superinterfaces:
Docile
- All Known Implementing Classes:
Doc.Cat,Doc.CodeBlock,Doc.Column,Doc.Empty,Doc.EscapedText,Doc.FlatAlt,Doc.HyperLinked,Doc.Image,Doc.InlineCode,Doc.Line,Doc.List,Doc.Nest,Doc.Nesting,Doc.PageWidth,Doc.PlainText,Doc.SpecialSymbol,Doc.Styled,Doc.Union
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordConcatenation of two documentsstatic final recordCode block, with special escape settings compared toDoc.PlainTextstatic final recordA document that will react on the current cursor position.static final recordThe empty document; conceptually the unit of 'Cat'static final recordAlready escaped text, which will not be escaped by backend.static final recordLay out the defaultDoc 'Doc', but when flattened (via 'group'), prefer the preferWhenFlatten.static final recordA clickable text line without '\n'.static final recordstatic final recordInline code, with special escape settings compared toDoc.PlainTextstatic final recordHard line breakstatic final recordstatic final recordDocument indented by a number of columnsstatic final recordA document that will react on the current nest level.static final recordA document that will react on the page width.static final recordA plain text line without '\n'.static final recordA special symbol that may get rendered in a special waystatic final recordStyled documentstatic final recordThe first lines of first document should be shorter than the first lines of the second one, so the layout algorithm can pick the one that fits best. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull Docalign lays out the document with the nesting level set to the current column.static @NotNull Docdefault @NotNull kala.collection.SeqLike<Doc>asSeq()static @NotNull Docstatic @NotNull DocbracedUnless(Doc doc, boolean falsification) static @NotNull Docstatic @NotNull Doccat tries laying out the documents separated with nothing, and if this does not fit the page, separates them with newlines.static @NotNull Docstatic @NotNull DoccatBlockL(int minBeforeRight, @NotNull kala.collection.SeqLike<Doc> left, @NotNull Doc delim, @NotNull kala.collection.SeqLike<Doc> right) static @NotNull DoccatBlockR(int minBeforeDelim, @NotNull kala.collection.SeqLike<Doc> left, @NotNull Doc delim, @NotNull kala.collection.SeqLike<Doc> right) static @NotNull DocCreates a C-style indented block of statements.static @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Doccolumn(@NotNull IntFunction<Doc> docBuilder) Layout a document depending on which column it starts at.static @NotNull Docdefault @NotNull StringProduce unicode and 80-width outputdefault @NotNull StringProduce ASCII and infinite-width outputstatic @NotNull Docempty()The empty document; conceptually the unit of 'Cat'static @NotNull DocReturn conditionalempty()static @NotNull Docstatic @NotNull DocAlready escaped text that will be rendered as-is.static @NotNull DocBy default, flatAlt renders as .static @NotNull DocflatAltBracedBlock(Doc defaultDoc, Doc flatDoc) Either `{ defaultDoc }` or `{\nflatDoc\n}`static @NotNull Dochang lays out the document with a nesting level set to the /current column/ plus .static @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull DocThis method indent document by columns, * starting from the current cursor position.default booleanisEmpty()default booleanstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docline()Unconditionally line breakstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Doclays out the document with the current nesting level (indentation of the following lines) increased by .static @NotNull Docnesting(@NotNull IntFunction<Doc> docBuilder) Layout a document depending on the current 'nest'-ing level.static @NotNull Docstatic @NotNull Docordinal(int n) static @NotNull DocpageWidth(@NotNull IntFunction<Doc> docBuilder) Layout a document depending on the page width, if one has been specified.static @NotNull DocParagraph indentation: indent by columns, and then indent the first line again by columns.static @NotNull Docstatic @NotNull DocPlain text document.default <Out,Config extends PrinterConfig>
Outdefault @NotNull Stringdefault @NotNull Stringdefault @NotNull StringrenderToHtml(boolean withHeader) default @NotNull Stringdefault @NotNull StringrenderToString(int pageWidth, boolean unicode) default @NotNull StringrenderToString(@NotNull StringPrinterConfig<?> config) default @NotNull Stringdefault @NotNull StringrenderToTerminal(int pageWidth, boolean unicode) default @NotNull Stringstatic @NotNull Docstatic @NotNull DocfillSep concatenates the documents horizontally with a space as long as it fits the page, then inserts a 'line' and continues doing that for all documents in .static @NotNull DocsepNonEmpty(@NotNull kala.collection.SeqLike<Doc> docs) static @NotNull DocsepNonEmpty(Doc @NotNull ... docs) static @NotNull Docstatic @NotNull Docspaces(int n) static @NotNull DocConcat , and , with and occupying at least length.static @NotNull DocConcat , and , with occupying at least length.static @NotNull DocstickySep concatenates all documents horizontally with a space, i.e.static @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docstatic @NotNull Docdefault @NotNull DoctoDoc()static @NotNull Docstatic @NotNull Docstatic @NotNull DocvcatNonEmpty(@NotNull kala.collection.SeqLike<Doc> docs) static @NotNull DocvcatNonEmpty(Doc @NotNull ... docs) static @NotNull DocvcommaList(@NotNull kala.collection.SeqLike<Doc> docs) static @NotNull Doc
-
Field Details
-
ONE_WS
-
ALT_WS
-
COMMA
-
-
Method Details
-
isNotEmpty
default boolean isNotEmpty() -
isEmpty
default boolean isEmpty() -
toDoc
-
asSeq
- Returns:
- a seq with cats flattened
-
renderToString
-
renderToString
-
renderToTerminal
-
renderToTerminal
-
renderToHtml
-
renderToHtml
-
renderToMd
-
renderToAyaMd
-
renderToTeX
-
render
@NotNull default <Out,Config extends PrinterConfig> Out render(@NotNull @NotNull Printer<Out, Config> printer, @NotNull Config config) -
debugRender
Produce ASCII and infinite-width output -
commonRender
Produce unicode and 80-width output -
linkDef
-
linkRef
-
linkDef
-
linkRef
-
hyperLink
-
hyperLink
-
image
-
code
-
code
-
code
-
codeBlock
-
codeBlock
-
styled
-
styled
-
styled
-
styled
-
licit
-
spaced
-
wrap
-
bracedUnless
- Parameters:
falsification- when false, add braces
-
braced
-
flatAltBracedBlock
Either `{ defaultDoc }` or `{\nflatDoc\n}` -
angled
-
parened
-
emptyIf
Return conditionalempty()- Parameters:
cond- conditionotherwise- otherwise- Returns:
Doc.Emptywhencondis true, otherwiseotherwise
-
empty
The empty document; conceptually the unit of 'Cat'- Returns:
- empty document
-
flatAlt
@Contract("_, _ -> new") @NotNull static @NotNull Doc flatAlt(@NotNull @NotNull Doc defaultDoc, @NotNull @NotNull Doc preferWhenFlattened) By default, flatAlt renders as . However, when 'group'-ed, will be preferred, with as the fallback for the case when doesn't fit.- Parameters:
defaultDoc- default documentpreferWhenFlattened- document selected when flattened- Returns:
- alternative document
-
column
@Contract("_ -> new") @NotNull static @NotNull Doc column(@NotNull @NotNull IntFunction<Doc> docBuilder) Layout a document depending on which column it starts at.align(Doc)is implemented in terms ofcolumn.- Parameters:
docBuilder- document generator when current position provided- Returns:
- column action document
-
nesting
@Contract("_ -> new") @NotNull static @NotNull Doc nesting(@NotNull @NotNull IntFunction<Doc> docBuilder) Layout a document depending on the current 'nest'-ing level.align(Doc)is implemented in terms ofnesting.- Parameters:
docBuilder- document generator when current nest level provided- Returns:
- nest level action document
-
pageWidth
@Contract("_ -> new") @NotNull static @NotNull Doc pageWidth(@NotNull @NotNull IntFunction<Doc> docBuilder) Layout a document depending on the page width, if one has been specified.- Parameters:
docBuilder- document generator when page width provided- Returns:
- page width action document
-
nest
lays out the document with the current nesting level (indentation of the following lines) increased by . Negative values are allowed, and decrease the nesting level accordingly.For differences between
hang(int, Doc),indent(int, Doc)andnest(int, Doc), see unit tests in file "DocStringPrinterTest.java".- Parameters:
indent- indentation of the following linesdoc- the document to lay out- Returns:
- indented document
-
align
align lays out the document with the nesting level set to the current column. It is used for example to implementhang(int, Doc).As an example, we will put a document right above another one, regardless of the current nesting level. Without 'align'-ment, the second line is put simply below everything we've had so far,
If we add an 'align' to the mix, the @'vsep'@'s contents all start in the same column,
- Parameters:
doc- document to be aligned- Returns:
- aligned document
-
hang
@Contract("_, _ -> new") @NotNull static @NotNull Doc hang(int deltaNest, @NotNull @NotNull Doc doc) hang lays out the document with a nesting level set to the /current column/ plus . Negative values are allowed, and decrease the nesting level accordingly.This differs from
nest(int, Doc), which is based on the /current nesting level/ plusindent. When you're not sure, try the more efficient 'nest' first. In our example, this would yieldFor differences between
hang(int, Doc),indent(int, Doc)andnest(int, Doc), see unit tests in file "DocStringPrinterTest.java".- Parameters:
deltaNest- change of nesting level, relative to the start of the first linedoc- document to indent- Returns:
- hang-ed document
-
indent
This method indent document by columns, * starting from the current cursor position.This differs from
hang(int, Doc), which starts from the next line.For differences between
hang(int, Doc),indent(int, Doc)andnest(int, Doc), see unit tests in file "DocStringPrinterTest.java".- Parameters:
indent- Number of spaces to increase indentation by- Returns:
- The indented document
-
spaces
-
par
Paragraph indentation: indent by columns, and then indent the first line again by columns. This should be used at the line start. -
splitR
@NotNull static @NotNull Doc splitR(int minBeforeDelim, @NotNull @NotNull Doc left, @NotNull @NotNull Doc delim, @NotNull @NotNull Doc right) Concat , and , with occupying at least length. The "R" in method name stands for "right", which means the delim is placed near the right.This behaves like
printf("%-*s%s%s", minBeforeDelim, left, delim, right);For example:var doc = split(8, plain("Help"), plain(":"), english("Show the help message")); assertEquals("Help :Show the help message", doc.commonRender());- Parameters:
minBeforeDelim- The minimum length before- API Note:
- , , should all be 1-line documents
-
splitL
@NotNull static @NotNull Doc splitL(int minBeforeRight, @NotNull @NotNull Doc left, @NotNull @NotNull Doc delim, @NotNull @NotNull Doc right) Concat , and , with and occupying at least length. The "L" in method name stands for "left", which means the delim is placed near the left.This behaves like
printf("%*s%s", minBeforeRight, (left ++ delim), right);For example:var doc = splitR(8, plain("Help"), plain(":"), english("Show the help message")); assertEquals("Help: Show the help message", doc.commonRender());- Parameters:
minBeforeRight- The minimum length before- API Note:
- , , should all be 1-line documents
-
catBlockR
-
catBlockL
-
cblock
@Contract("_, _, _ -> new") @NotNull static @NotNull Doc cblock(@NotNull @NotNull Doc prefix, int indent, @NotNull @NotNull Doc block) Creates a C-style indented block of statements.prefix { [indent]block } -
ordinal
-
plain
Plain text document. Backend will escape the text if it contains offending characters.- Parameters:
text- text that may not contain '\n'- Returns:
- text document of the whole text
-
escaped
Already escaped text that will be rendered as-is. Callers should be responsible for escaping offending characters (like '\n', 'invalid input: '<'', etc.) depending on the backend. Use with care as this may result in invalid output format.Note that this is not the same as
code(java.lang.String)orcodeBlock(java.lang.String). Although in most cases code segments are treated as "already escaped" text that will be rendered as-is. But for HTML, code segments is still escaped because they are placed in `` and ``.
- Parameters:
text- text that will be rendered as-is.
-
english
-
symbol
- Parameters:
text- '\n' not allowed!- Returns:
- special symbol
-
cat
@Contract("_ -> new") @NotNull static @NotNull Doc cat(@NotNull @NotNull kala.collection.SeqLike<Doc> docs) cat tries laying out the documents separated with nothing, and if this does not fit the page, separates them with newlines. This is what differentiates it from 'vcat', which always lays out its contents beneath each other.- Parameters:
docs- documents to concat- Returns:
- cat document
-
cat
- See Also:
-
vcat
-
vcat
-
vcatNonEmpty
-
vcatNonEmpty
-
list
-
ordered
-
bullet
-
stickySep
@Contract("_ -> new") @NotNull static @NotNull Doc stickySep(@NotNull @NotNull kala.collection.SeqLike<@NotNull Doc> docs) stickySep concatenates all documents horizontally with a space, i.e. it puts a space between all entries.stickySep does not introduce line breaks on its own, even when the page is too narrow:
- Parameters:
docs- documents to separate- Returns:
- separated documents
-
stickySep
-
sep
fillSep concatenates the documents horizontally with a space as long as it fits the page, then inserts a 'line' and continues doing that for all documents in . 'line' means that if 'group'-ed, the documents are separated with a 'space' instead of newlines. Usecat(kala.collection.SeqLike<org.aya.pretty.doc.Doc>)if you do not want a 'space'.Let's print some words to fill the line:
- Parameters:
docs- documents to separate- Returns:
- separated documents
-
sep
-
sepNonEmpty
-
sepNonEmpty
-
commaList
-
vcommaList
-
join
-
join
-
line
Unconditionally line break- Returns:
- hard line document
-