@boba-cli/cursor
v0.1.0-alpha.3
Published
Cursor component for Boba terminal UIs
Readme
@boba-cli/cursor
Cursor component for Boba terminal UIs. Handles blinking, focus, and hidden/static modes.
Install
pnpm add @boba-cli/cursorQuickstart
import {
CursorModel,
CursorMode,
BlinkMsg,
InitialBlinkMsg,
} from '@boba-cli/cursor'
import type { Cmd, Msg } from '@boba-cli/tea'
// Create a cursor (defaults to blink mode)
let cursor = new CursorModel()
// In init, start blinking
function init(): Cmd<Msg> {
return cursor.initBlink()
}
// In update, handle focus/blur and blink messages
function update(msg: Msg): [MyModel, Cmd<Msg>] {
const [nextCursor, cmd] = cursor.update(msg)
cursor = nextCursor
return [model, cmd]
}
// In view, render the cursor at your desired position/character
function view(): string {
return cursor.view()
}Modes
| Mode | Behavior |
| ------------------- | ----------------------------------------------- |
| CursorMode.Blink | Toggles between block and text state on a timer |
| CursorMode.Static | Always shows the block |
| CursorMode.Hidden | Always shows text (cursor hidden) |
API
| Export | Description |
| ----------------- | ----------------------------------- |
| CursorModel | Main component model |
| CursorMode | Enum of Blink, Static, Hidden |
| BlinkMsg | Blink toggle message |
| InitialBlinkMsg | Kickoff message for blinking |
CursorModel helpers
| Method | Description |
| -------------------- | ---------------------------------------------- |
| id() | Unique ID for routing |
| mode() | Current mode |
| initBlink() | Command to send an initial blink message |
| tickBlink() | Command to schedule the next blink |
| withMode(mode) | Change mode (returns new model + optional cmd) |
| withChar(char) | Change the underlying character |
| focus() / blur() | Focus management (returns new model) |
| update(msg) | Handle messages; returns [model, cmd] |
| view() | Render the cursor |
Scripts
pnpm -C packages/cursor buildpnpm -C packages/cursor testpnpm -C packages/cursor lintpnpm -C packages/cursor generate:api-report
License
MIT
