@boba-cli/textinput 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -0
- package/dist/index.cjs +665 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +173 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.js +650 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @boba-cli/textinput
|
|
2
|
+
|
|
3
|
+
Single-line text input component for Boba terminal UIs. Port of Charmbracelet Bubbles textinput.
|
|
4
|
+
|
|
5
|
+
<img src="../../examples/textinput-demo.gif" width="950" alt="Textinput component demo" />
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @boba-cli/textinput
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { TextInputModel, EchoMode } from '@boba-cli/textinput'
|
|
17
|
+
import type { Cmd, Msg } from '@boba-cli/tea'
|
|
18
|
+
|
|
19
|
+
let input = TextInputModel.new({
|
|
20
|
+
placeholder: 'Type your name…',
|
|
21
|
+
width: 40,
|
|
22
|
+
echoMode: EchoMode.Normal,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
function init(): Cmd<Msg> {
|
|
26
|
+
const [focused, cmd] = input.focus()
|
|
27
|
+
input = focused
|
|
28
|
+
return cmd
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function update(msg: Msg): [typeof model, Cmd<Msg>] {
|
|
32
|
+
const [nextInput, cmd] = input.update(msg)
|
|
33
|
+
input = nextInput
|
|
34
|
+
return [model, cmd]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function view(): string {
|
|
38
|
+
return ['Name:', input.view()].join('\n')
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- Grapheme-aware cursor movement and editing
|
|
45
|
+
- Placeholder text when empty
|
|
46
|
+
- Password/hidden echo modes and custom echo character
|
|
47
|
+
- Character limit enforcement
|
|
48
|
+
- Width-constrained rendering with horizontal scrolling
|
|
49
|
+
- Clipboard paste (uses `clipboardy`)
|
|
50
|
+
- Validation callback
|
|
51
|
+
|
|
52
|
+
## Key bindings (defaults)
|
|
53
|
+
|
|
54
|
+
- Move: `left/right`, `ctrl+b/ctrl+f`
|
|
55
|
+
- Word move: `alt+left/right`, `ctrl+left/right`, `alt+b/alt+f`
|
|
56
|
+
- Delete char: `backspace`, `delete`, `ctrl+h`, `ctrl+d`
|
|
57
|
+
- Delete word: `alt+backspace`, `alt+delete`, `ctrl+w`, `alt+d`
|
|
58
|
+
- Delete to start/end: `ctrl+u`, `ctrl+k`
|
|
59
|
+
- Home/end: `home`, `end`, `ctrl+a`, `ctrl+e`
|
|
60
|
+
- Paste: `ctrl+v`
|
|
61
|
+
|
|
62
|
+
## API
|
|
63
|
+
|
|
64
|
+
- `TextInputModel.new(options)` – create a model
|
|
65
|
+
- `model.focus()/blur()` – toggle focus (returns new model, plus optional command)
|
|
66
|
+
- `model.update(msg)` – handle Tea messages, returns `[model, cmd]`
|
|
67
|
+
- `model.view()` – render with prompt and cursor
|
|
68
|
+
- Editing helpers: `insertRunes`, `deleteLeft/Right`, `wordLeft/Right`, `deleteWordLeft/Right`, `deleteToStart/End`, `reset`
|
|
69
|
+
- Validation: `setValidateFunc(fn)`, `validate()`
|
|
70
|
+
- Clipboard: `paste()` (returns `[model, cmd]`) or use `pasteCommand`
|
|
71
|
+
|
|
72
|
+
## Scripts
|
|
73
|
+
|
|
74
|
+
- `pnpm -C packages/textinput build`
|
|
75
|
+
- `pnpm -C packages/textinput test`
|
|
76
|
+
- `pnpm -C packages/textinput lint`
|
|
77
|
+
- `pnpm -C packages/textinput generate:api-report`
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT
|