Table of Contents

Class Buffer

Namespace
MiniTui
Assembly
MiniTui.dll

Off-screen buffer for rendering. This is your canvas.

public class Buffer
Inheritance
Buffer
Inherited Members

Remarks

No drawing method throws for any coordinates or Rect: out-of-bounds writes are ignored. Wide characters always occupy two cells, a head and a continuation, and are never split.

Constructors

Buffer(int, int)

Create a new buffer with the specified dimensions. Negative sizes are treated as zero.

public Buffer(int width, int height)

Parameters

width int
height int

Properties

Area

The full buffer area as a Rect.

public Rect Area { get; }

Property Value

Rect

CursorRequest

Where the visible terminal cursor should be shown this frame, or null to hide it. Set with SetCursor(int, int); reset by Clear().

public (int X, int Y)? CursorRequest { get; }

Property Value

(int X, int Y)?

Height

Buffer height in cells.

public int Height { get; }

Property Value

int

Width

Buffer width in cells.

public int Width { get; }

Property Value

int

Methods

Clear()

Clear the buffer to empty cells and drop any cursor request.

public void Clear()

DrawHLine(int, int, int, char, Style)

Draw a horizontal line of c, patching each cell with style.

public void DrawHLine(int x, int y, int length, char c = '─', Style style = default)

Parameters

x int
y int
length int
c char
style Style

DrawVLine(int, int, int, char, Style)

Draw a vertical line of c, patching each cell with style.

public void DrawVLine(int x, int y, int length, char c = '│', Style style = default)

Parameters

x int
y int
length int
c char
style Style

Fill(Cell)

Fill the entire buffer with a cell.

public void Fill(Cell cell)

Parameters

cell Cell

FillRect(Rect, Cell)

Fill a rectangular area with a cell.

public void FillRect(Rect rect, Cell cell)

Parameters

rect Rect
cell Cell

Get(int, int)

Get a cell at the given position. Returns empty cell for out-of-bounds.

public Cell Get(int x, int y)

Parameters

x int
y int

Returns

Cell

Set(int, int, Cell)

Set a cell at the given position. Ignores out-of-bounds coordinates. The symbol is sanitized (a zero-width symbol becomes a space), and wide characters overwrite the cell to their right. A wide character that would start in the last column is written as a space.

public void Set(int x, int y, Cell cell)

Parameters

x int
y int
cell Cell

SetCursor(int, int)

Request that the visible terminal cursor be shown at this position for this frame. Out-of-bounds positions are ignored.

public void SetCursor(int x, int y)

Parameters

x int
y int

SetLine(int, int, Line, int)

Write a line of styled spans, up to maxWidth columns. Like Ratatui's set_line, this ignores Alignment.

public int SetLine(int x, int y, Line line, int maxWidth)

Parameters

x int
y int
line Line
maxWidth int

Returns

int

The number of columns advanced.

SetString(int, int, ReadOnlySpan<char>, Style, int)

Write a single line of text, patching each cell with style. Control characters are sanitized; tabs and line breaks become spaces. Stops at maxWidth columns or the buffer edge, and never writes half of a wide character.

public int SetString(int x, int y, ReadOnlySpan<char> text, Style style, int maxWidth = 2147483647)

Parameters

x int
y int
text ReadOnlySpan<char>
style Style
maxWidth int

Returns

int

The number of columns advanced.

SetStyle(Rect, Style)

Patch the style of every cell in area, keeping the symbols.

public void SetStyle(Rect area, Style style)

Parameters

area Rect
style Style

ToLines()

The buffer's symbols, one string per row, with continuation cells omitted. Intended for tests.

public string[] ToLines()

Returns

string[]