Table of Contents

Class AnsiOutput

Namespace
Terminal.Gui.Drivers
Assembly
Terminal.Gui.dll

Pure ANSI console output.

ANSI Output Architecture:

  • Pure ANSI - All output operations use ANSI escape sequences via EscSeqUtils, making it portable across ANSI-compatible terminals (Unix, Windows Terminal, ConEmu, etc.).
  • Buffer Capture - GetLastBuffer() provides access to the last written IOutputBuffer for test verification, independent of actual console output.
  • Graceful Degradation - Detects if console is unavailable or redirected, silently operating in buffer-only mode for CI/headless environments.
  • Size Management - Uses SetSize(int, int) for controlling terminal dimensions in tests. In real terminals, size would be queried via ANSI requests (see CSI_ReportWindowSizeInChars) or platform APIs.

Color Support: Supports both 16-color (via Force16Colors) and true-color (24-bit RGB) output through ANSI SGR sequences.

public class AnsiOutput : OutputBase, IOutput, IDisposable
Inheritance
AnsiOutput
Implements
Inherited Members

Constructors

AnsiOutput()

Initializes a new instance of AnsiOutput. Checks if a real console is available for ANSI output and activates the alternate screen buffer.

Methods

AppendOrWriteAttribute(StringBuilder, Attribute, TextStyle)

Changes the color and text style of the console to the given attr and redrawTextStyle. If command can be buffered in line with other output (e.g. CSI sequence) then it should be appended to output otherwise the relevant output state should be flushed directly (e.g. by calling relevant win 32 API method)

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

GetCursor()

Gets the current cursor for this output.

GetLastBuffer()

Gets or sets the last output buffer written. The Contents contains a reference to the buffer last written with Write(IOutputBuffer).

GetSize()

Returns the current size of the console in rows/columns (i.e. of characters not pixels).

HandleSizeQueryResponse(string?)

Handles ANSI size query responses. Expected format: ESC [ 8 ; height ; width t

SetCursor(Cursor)

Sets the cursor for this output.

SetCursorPositionImpl(int, int)

When overriden in derived class, positions the terminal draw cursor to the specified point on the screen. Note, this does NOT update any internal cursor position state - that is the responsibility of the caller.

SetSize(int, int)

Sets the size of the console.

Write(ReadOnlySpan<char>)

Writes the given text directly to the console. Use to send ansi escape codes etc. Regular screen output should use the IOutputBuffer overload.

Write(StringBuilder)

Output the contents of the output to the console.

Write(IOutputBuffer)

Write the contents of the buffer to the console