Class AnsiSink
Style handling is deterministic and diffed: an escape sequence is emitted only when the
foreground, background, or text decorations change; all changed attributes coalesce into a single
sequence; and a null colour channel resolves to the ANSI default (39/49)
rather than "leave as-is". Decoration flags emit attribute on/off codes (bold 1/22, italic 3/23,
underline 4/24) diffed against the previous style. A reset (ItTiger.TigerCli.Terminal.AnsiSgr.Reset) — which
also clears decorations — is emitted before each newline and on flush whenever a style is active,
so a styled background never bleeds past the line.
This is TigerCli's terminal renderer, so it is terminal-bounded by default: it reports the terminal's width and height to the measure pass exactly as ItTiger.TigerCli.Terminal.ConsoleSink does, and structured output wraps in the layout rather than relying on the terminal's own auto-wrap. Pass Buffer when the writer is a string, file, or capture stream, so the render stays content-driven and identical on every machine.
public sealed class AnsiSink : ICliRenderSink
- Inheritance
-
AnsiSink
- Implements
- Inherited Members
Constructors
AnsiSink(TextWriter, bool, bool, CliSinkTarget)
emitHyperlinks is true, text runs carrying
a HyperlinkTarget are wrapped in OSC 8 hyperlink sequences (the
visible text is always written regardless). Defaults to false so existing direct callers
(and tests) emit no hyperlink sequences unless they opt in; ItTiger.TigerCli.Terminal.ConsoleSinkFactory
sets it from HyperlinkMode.public AnsiSink(TextWriter writer, bool emitHyperlinks = false, bool emitTerminalControls = true, CliSinkTarget target = CliSinkTarget.Terminal)
Parameters
writerTextWriter- The destination writer.
emitHyperlinksbool- Whether to emit OSC 8 hyperlink sequences.
emitTerminalControlsbool- Whether to emit terminal control sequences such as the window title.
targetCliSinkTarget- What the sink writes to, which decides the layout bounds it reports.
Defaults to Terminal: a plain
new AnsiSink(Console.Out)is a terminal renderer and wraps to the terminal's width without further wiring. Use Buffer for a string, file, or capture writer.
Exceptions
- ArgumentNullException
writerisnull.
Properties
MaxHeight
null when unbounded.public int? MaxHeight { get; }
Property Value
- int?
MaxWidth
null when unbounded.public int? MaxWidth { get; }
Property Value
- int?
SoftMaxHeight
null when unbounded.public int? SoftMaxHeight { get; }
Property Value
- int?
SoftMaxWidth
null when unbounded.public int? SoftMaxWidth { get; }
Property Value
- int?
Remarks
Target
public CliSinkTarget Target { get; }
Property Value
Methods
Flush()
public void Flush()
NewLine()
public void NewLine()
Reset()
public void Reset()
SetWindowTitle(string)
public void SetWindowTitle(string title)
Parameters
titlestring- The window title to set.
Write(CliTextSegment)
public void Write(CliTextSegment segment)
Parameters
segmentCliTextSegment- The styled text segment to write.