Table of Contents

Class RatatuiRenderer

Namespace
RatatuiUnity

MonoBehaviour that renders a Ratatui terminal to a UnityEngine.Texture2D and optionally assigns it to a UI UnityEngine.UI.RawImage or a MeshRenderer material each frame. When no target is assigned, falls back to OnGUI rendering. Use Full to stretch the terminal to the entire screen, Partial to draw at native pixel size with configurable alignment, or Window for a draggable macOS-style window whose title bar shows gameObject.name.

Override BuildFrame(RatatuiTerminal) to define widget layout. Override OnTerminalKeyDown(TerminalKeyEvent), OnTerminalMouseEvent(TerminalMouseEvent), and OnTerminalHoverChanged(TerminalHoverState, TerminalHoverState) to handle input events.

public class RatatuiRenderer : MonoBehaviour
Inheritance
Object
MonoBehaviour
RatatuiRenderer
Inherited Members

Properties

HoverState

Current mouse hover state in terminal coordinates.

public TerminalHoverState HoverState { get; }

Property Value

TerminalHoverState

Terminal

The underlying terminal instance.

public RatatuiTerminal Terminal { get; }

Property Value

RatatuiTerminal

Texture

The rendered texture. Assign to any Unity material or UI image.

public Texture2D Texture { get; }

Property Value

Texture2D

Methods

Awake()

protected virtual void Awake()

BuildFrame(RatatuiTerminal)

Called every frame between BeginFrame and EndFrame. Override to define the terminal layout and widgets.

protected virtual void BuildFrame(RatatuiTerminal term)

Parameters

term RatatuiTerminal

FitRawImageToTexture()

Resizes the assigned RawImage's RectTransform to exactly match the terminal texture dimensions (1 texture pixel = 1 screen pixel at 100% scale).

public void FitRawImageToTexture()

OnDestroy()

protected virtual void OnDestroy()

OnGUI()

protected virtual void OnGUI()

OnTerminalHoverChanged(TerminalHoverState, TerminalHoverState)

Called when the hover state changes (mouse enters/exits areas or the terminal).

protected virtual void OnTerminalHoverChanged(TerminalHoverState oldState, TerminalHoverState newState)

Parameters

oldState TerminalHoverState
newState TerminalHoverState

OnTerminalKeyDown(TerminalKeyEvent)

Called for each keyboard event. Override to handle terminal key input.

protected virtual void OnTerminalKeyDown(TerminalKeyEvent e)

Parameters

e TerminalKeyEvent

OnTerminalMouseEvent(TerminalMouseEvent)

Called for mouse events (move, down, up, click, scroll). Override to handle terminal mouse input.

protected virtual void OnTerminalMouseEvent(TerminalMouseEvent e)

Parameters

e TerminalMouseEvent

TryGetTerminalCell(Vector2, out int, out int)

Converts a screen-space pixel position to terminal cell coordinates. Supports RawImage (UI), MeshRenderer (3D), and OnGUI fallback targets.

protected bool TryGetTerminalCell(Vector2 screenPos, out int col, out int row)

Parameters

screenPos Vector2
col int
row int

Returns

bool

Update()

protected virtual void Update()