|
| 1 | +# Cursor Protocol |
| 2 | + |
| 3 | +Rezi uses the **SET_CURSOR** command to control the terminal cursor position, |
| 4 | +visibility, shape, and blink state from the TypeScript renderer. |
| 5 | + |
| 6 | +## SET_CURSOR command |
| 7 | + |
| 8 | +**Opcode:** 7 (`OP_SET_CURSOR`) |
| 9 | + |
| 10 | +**Total size:** 20 bytes (8-byte command header + 12-byte payload) |
| 11 | + |
| 12 | +### Payload layout |
| 13 | + |
| 14 | +| Offset | Size | Type | Field | Description | |
| 15 | +|--------|------|------|-------|-------------| |
| 16 | +| 8 | 4 | `i32` | `x` | 0-based cell column; `-1` = leave unchanged | |
| 17 | +| 12 | 4 | `i32` | `y` | 0-based cell row; `-1` = leave unchanged | |
| 18 | +| 16 | 1 | `u8` | `shape` | Cursor shape constant | |
| 19 | +| 17 | 1 | `u8` | `visible` | `1` = show, `0` = hide | |
| 20 | +| 18 | 1 | `u8` | `blink` | `1` = blinking, `0` = steady | |
| 21 | +| 19 | 1 | `u8` | `reserved0` | Must be `0` | |
| 22 | + |
| 23 | +The command is 20 bytes total, which is 4-byte aligned (no padding needed). |
| 24 | + |
| 25 | +### Special values |
| 26 | + |
| 27 | +- **x = -1 or y = -1:** The engine leaves that coordinate unchanged from the previous frame. |
| 28 | +- **visible = 0:** Hides the cursor until a later command sets `visible = 1`. |
| 29 | + |
| 30 | +## Cursor shape constants |
| 31 | + |
| 32 | +The `shape` field accepts the following values, defined in `packages/core/src/abi.ts`: |
| 33 | + |
| 34 | +| Constant | Value | Description | |
| 35 | +|----------|-------|-------------| |
| 36 | +| `ZR_CURSOR_SHAPE_BLOCK` | `0` | Block cursor (full cell) | |
| 37 | +| `ZR_CURSOR_SHAPE_UNDERLINE` | `1` | Underline cursor (bottom of cell) | |
| 38 | +| `ZR_CURSOR_SHAPE_BAR` | `2` | Bar cursor (left edge of cell) | |
| 39 | + |
| 40 | +The TypeScript type is: |
| 41 | + |
| 42 | +```typescript |
| 43 | +export type CursorShape = 0 | 1 | 2; |
| 44 | +``` |
| 45 | + |
| 46 | +!!! note |
| 47 | + If the terminal does not support cursor shaping, the engine ignores `shape` |
| 48 | + and uses the terminal default cursor appearance. |
| 49 | + |
| 50 | +## Runtime behavior |
| 51 | + |
| 52 | +- The widget renderer resolves cursor targets from focused inputs/editors and |
| 53 | + emits `SET_CURSOR` when visible. |
| 54 | +- If no widget requests a cursor, the renderer emits a hide cursor command. |
| 55 | +- Node/Bun defaults to drawlist v5, so cursor protocol support is available by |
| 56 | + default. |
| 57 | + |
| 58 | +## Default cursor shapes |
| 59 | + |
| 60 | +The framework provides context-specific defaults in `CURSOR_DEFAULTS`: |
| 61 | + |
| 62 | +| Context | Shape | Blink | Use case | |
| 63 | +|---------|-------|-------|----------| |
| 64 | +| `input` | `2` (BAR) | `true` | Text input fields | |
| 65 | +| `selection` | `0` (BLOCK) | `true` | Selection-mode cursors | |
| 66 | +| `staticUnderline` | `1` (UNDERLINE) | `false` | Non-blinking indicator | |
| 67 | + |
| 68 | +```typescript |
| 69 | +import { CURSOR_DEFAULTS } from "@rezi-ui/core"; |
| 70 | + |
| 71 | +// CURSOR_DEFAULTS.input => { shape: 2, blink: true } |
| 72 | +// CURSOR_DEFAULTS.selection => { shape: 0, blink: true } |
| 73 | +// CURSOR_DEFAULTS.staticUnderline => { shape: 1, blink: false } |
| 74 | +``` |
| 75 | + |
| 76 | +## See also |
| 77 | + |
| 78 | +- [Drawlists (ZRDL)](zrdl.md) -- full ZRDL format reference |
| 79 | +- [Versioning](versioning.md) -- protocol and ABI version table |
0 commit comments