Read the root AGENTS.md first. This file adds widget-specific rules.
Display and data widgets that extend the Widget base class: Box, Text, Table, Gauge, Sparkline, Tree, LineChart, and 40+ more. Subfolders group by kind: display/, data/, input/, feedback/, layout/.
- Create
packages/widgets/src/<group>/<Name>.tsand<Name>.test.tsin the same folder. - Extend
Widgetfrom../base/Widget.js. - Implement
protected _renderSelf(screen: Screen): void. - Call
this.markDirty()in every method that changes visible state. - Export from
packages/widgets/src/index.ts.
Copy the structure of src/data/Gauge.ts and src/data/Gauge.test.ts. They show the constructor shape (label?, style = {}, opts = {}), the _renderSelf layout math, the caps.unicode fallback, and the test pattern using a real Screen.
_renderSelfreadsthis._getContentRect()for{ x, y, width, height }. Return early ifwidth <= 0 || height <= 0.- Draw with
screen.writeString(x, y, text, attrs)andscreen.setCell(x, y, { char, fg }). - Non-ASCII chars need a fallback:
caps.unicode ? '█' : '#'. - A widget that takes keys uses
handleKey(event: KeyEvent)with lowercase key names. - Import
Screen,Style,Color,KeyEvent,caps,styleToCellAttrs,stringWidthfrom@termuijs/core.
bun vitest run packages/widgets