Render
Render buffer for Basalt.
Holds the screen as three string arrays (text / fg / bg). Colors are stored as raw bytes (registry indices from core/palette), which is what allows more than 16 colors in the buffer. On flush, only lines that actually differ from what the terminal currently shows are blitted, and color bytes are translated to blit hex chars through the palette mapper.
Types
RenderLineBuffer
RenderLineBuffer = string[]RenderPixelRows
RenderPixelRows = string[]RenderPixelPalette
RenderPixelPalette = table<integer, string>RenderTerminal
extends PaletteTerminal
| Field | Type | Description |
|---|---|---|
| getSize | fun(): integer, integer | |
| setCursorPos | fun(x: number, y: number) | |
| setCursorBlink | fun(blink: boolean) | |
| setTextColor | fun(color: number) | |
| blit | fun(text: string, foreground: string, background: string) |
Methods
Render.new(t)
Creates a retained terminal render buffer.
t (
RenderTerminal) Terminal-like targetreturns buffer (
Render)
Render:resize(w, h)
Resizes and clears the retained buffer.
w (
integer) Widthh (
integer) Heightreturns (
self)
Render:push(x, y, w, h)
Pushes a child region: translates the origin to (x, y) in the current space and intersects the clip rect with the w*h area.
x (
number) Child x positiony (
number) Child y positionw (
number) Child widthh (
number) Child heightreturns (
self)
Render:pop()
Restores the previous origin and clipping rectangle.
- returns (
self)
Render:write(x, y, str, fgChar, bgChar)
Core write. fgChar/bgChar are single-byte strings or nil (keep existing).
x (
number) X positiony (
number) Y positionstr (
string) Text to writefgChar (
string, optional) Encoded foreground bytesbgChar (
string, optional) Encoded background bytesreturns (
self)
Render:blit(x, y, str, fg, bg)
Writes text with optional fg/bg colors (public color values, nil = keep).
x (
number) X positiony (
number) Y positionstr (
string) Text to writefg (
number|false, optional) Foreground color; false keeps the existing colorbg (
number|false, optional) Background color; false keeps the existing colorreturns (
self)
Render:colorBlit(x, y, str, foregrounds, backgrounds)
Writes a row whose cells may each use a different public color value. This is the efficient path for custom-painted editors and charts: it performs one clipped line splice instead of one splice per cell.
x (
number) X positiony (
number) Y positionstr (
string) Text to writeforegrounds (
number[]) Foreground color for each characterbackgrounds (
number[]) Background color for each characterreturns (
self)
Render:drawText(x, y, str)
Writes plain text, keeping the colors underneath. (named drawText because .text is the buffer's line array)
x (
number) X positiony (
number) Y positionstr (
string) Text to writereturns (
self)
Render:rawBlit(x, y, str, fgStr, bgStr)
Writes a pre-encoded span: fgStr/bgStr are byte strings (registry indices) with the same length as str, or nil to keep existing colors.
x (
number) X positiony (
number) Y positionstr (
string) Text to writefgStr (
string, optional) Encoded foreground bytesbgStr (
string, optional) Encoded background bytesreturns (
self)
Render:maskedBlit(x, y, str, fgStr, bgStr, textMask, fgMask, bgMask)
x (
number) X positiony (
number) Y positionstr (
string) Text planefgStr (
string, optional) Encoded foreground planebgStr (
string, optional) Encoded background planetextMask (
string, optional) Text visibility maskfgMask (
string, optional) Foreground visibility maskbgMask (
string, optional) Background visibility maskreturns (
self)
Render:drawPixels(x, y, pixelWidth, pixelHeight, rows, paletteBytes)
x (
number) X position in terminal cellsy (
number) Y position in terminal cellspixelWidth (
integer) Source width in virtual pixelspixelHeight (
integer) Source height in virtual pixelsrows (
RenderPixelRows) Palette-index rows; byte zero is transparentpaletteBytes (
RenderPixelPalette) Palette index to registry bytereturns (
self)
Render:drawBlit(x, y, str, fgHex, bgHex)
Writes a blit triple with hex color strings ("0"-"f"), e.g. straight from window.getLine() — used to embed foreign terminal content.
x (
number) X positiony (
number) Y positionstr (
string) Text to writefgHex (
string, optional) Foreground blit stringbgHex (
string, optional) Background blit stringreturns (
self)
Render:fill(x, y, w, h, ch, fg, bg)
Fills a w*h area with a character and optional colors.
x (
number) X positiony (
number) Y positionw (
number) Widthh (
number) Heightch (
string) Fill characterfg (
number|false, optional) Foreground color; false keeps the existing colorbg (
number|false, optional) Background color; false keeps the existing colorreturns (
self)
Render:setCursor(x, y, blink, color)
Stores the cursor state to present during the next flush.
x (
number) Cursor xy (
number) Cursor yblink (
boolean) Blink statecolor (
number, optional) Cursor colorreturns (
self)
Render:flush()
Diffs the buffer against the terminal state and blits changed lines only.
- returns (
self)