This document captures design and implementation notes for TextFiglet.
For end-user usage and examples, see TextFiglet.
Func<string>).flf fonts)Markup or custom visuals for richer output)src/XenoAtom.Terminal.UI/Controls/TextFiglet.cssrc/XenoAtom.Terminal.UI/Styling/TextFigletStyle.cssrc/XenoAtom.Terminal.UI/Figlet/FigletFont.cssrc/XenoAtom.Terminal.UI/Figlet/FigletRenderOptions.cssrc/XenoAtom.Terminal.UI/Figlet/FigletPredefinedFont*.g.cs (embedded fonts, generated)src/XenoAtom.Terminal.UI.Tests/FigletTests.cssamples/ControlsDemo/Demos/TextFigletDemo.csTextFiglet : Visual (sealed)new TextFiglet()new TextFiglet(string text)new TextFiglet(Func<string> textProvider)
Text : string? (bindable)Font : FigletFont? (bindable)LetterSpacing : int (bindable)
>= 0.TrimTrailingSpaces : bool (bindable)MissingGlyph : char (bindable)TextAlignment : TextAlignment (bindable)
Defaults (constructor):
Font = FigletFont.BlockLetterSpacing = 1TrimTrailingSpaces = trueMissingGlyph = '?'TextAlignment = TextAlignment.LeftThere are no events and no input handling.
FigletFont represents a FIGlet font (typically from a .flf file):
Height (number of rows per glyph)Font sources:
FigletFont.Block (built-in lazy-loaded block font)FigletPredefinedFont.* (generated, lazy-loaded)FigletFont.Load(path) or FigletFont.Load(stream)FigletFont.RenderLines(...) behavior:
Height strings (one string per row), or empty if input is empty\r) are ignored\n) are currently treated as spaces (v1 choice); users can stack multiple TextFiglet controls to render
multiple banner paragraphsMissingGlyph (default ?)LetterSpacing inserts spaces between characters after the first rendered characterTrimTrailingSpaces trims spaces on each output line after renderTextFiglet caches the rendered lines and computed width.
Cache key:
Font is compared by reference (ReferenceEquals)Text is compared ordinallyFigletRenderOptions record struct)When the cache is invalidated, TextFiglet calls font.RenderLines(text, options) and then computes:
_cachedWidth as the maximum cell width across all rendered lines (TerminalTextUtility.GetWidth(...))This makes measure/render cheap when the inputs are stable.
Measure forces the cache to be up-to-date, then returns a fixed desired size:
_cachedWidth_cachedLines.LengthThe size is clamped to the provided constraints.
Render:
min(Bounds.Height, _cachedLines.Length) linesx = Bounds.Xx = Bounds.X + ((Bounds.Width - lineWidth) / 2)x = Bounds.X + (Bounds.Width - lineWidth)Important details:
TerminalTextUtility.GetWidth).CellBuffer.WriteText(...) performs the final clipping to the buffer.Border or Padder) or apply a
background style in an ancestor that fills the area.TextFigletStyle currently controls only the style used to draw the banner text:
TextStyle : Style?
theme.ForegroundTextStyle()Note: despite the property name, TextFigletStyle.TextStyle is a Style (foreground/background/decorations), not a
TextStyle enum value.
FigletTests cover:
.flf fontsFigletFont.RenderLines producing multi-line output for a block fontTextFiglet rendering with a custom block font (ensures expected characters appear)\n as paragraph breaks) behind a flag or separate control.