$git clone https://github.com/wobsoriano/bun-promptxbun-promptx is a terminal prompt library based on bubbles via bun:ffi.
| 1 | # bun-promptx |
| 2 | |
| 3 | bun-promptx is a terminal prompt library based on [bubbles](https://github.com/mritd/bubbles) via `bun:ffi`. |
| 4 | |
| 5 | ## Install |
| 6 | |
| 7 | ```bash |
| 8 | bun add bun-promptx |
| 9 | ``` |
| 10 | |
| 11 | ## Usage |
| 12 | |
| 13 | ### createSelection |
| 14 | |
| 15 | The `createSelection` function lets you create a terminal single-selection list prompt. It provides the functions of page up and down and key movement, and supports custom rendering methods. |
| 16 | |
| 17 | ```js |
| 18 | import { createSelection } from 'bun-promptx' |
| 19 | |
| 20 | const result = createSelection([ |
| 21 | { text: 'feat', description: 'Introducing new features' }, |
| 22 | { text: 'fix', description: 'Bug fix' }, |
| 23 | { text: 'docs', description: 'Writing docs' }, |
| 24 | { text: 'style', description: 'Improving structure/format of the code' }, |
| 25 | { text: 'refactor', description: 'Refactoring code' }, |
| 26 | { text: 'test', description: 'Refactoring code' }, |
| 27 | { text: 'chore', description: 'When adding missing tests' }, |
| 28 | { text: 'perf', description: 'Improving performance' } |
| 29 | ], { |
| 30 | headerText: 'Select Commit Type: ', |
| 31 | perPage: 5, |
| 32 | footerText: 'Footer here' |
| 33 | }) |
| 34 | |
| 35 | console.log(result) |
| 36 | // { selectedIndex: 2, error: null } |
| 37 | ``` |
| 38 | |
| 39 | <img src="https://i.imgur.com/yE0qKyA.gif" alt="promptx demo" width="500" /> |
| 40 | |
| 41 | ### createPrompt |
| 42 | |
| 43 | The `createPrompt` function is a terminal input prompt library. It provides CJK character support and standard terminal shortcut keys (such as ctrl+a, ctrl+e), password input echo and other functions. |
| 44 | |
| 45 | ```js |
| 46 | import { createPrompt } from 'bun-promptx' |
| 47 | |
| 48 | const username = createPrompt("Enter username: ") |
| 49 | // { value: "wobsoriano", error: null } |
| 50 | |
| 51 | const password = createPrompt("Enter password: ", { |
| 52 | echoMode: 'password' |
| 53 | }) |
| 54 | // { value: "123456", error: null } |
| 55 | ``` |
| 56 | |
| 57 | <img src="https://i.imgur.com/wx6BTUm.gif" alt="promptx demo" width="500" /> |
| 58 | |
| 59 | ## License |
| 60 | |
| 61 | MIT |