tui-prompts
A Ratatui widget set for friendly prompts and input flows. Part of the tui-widgets suite by Joshka.
GitHub Repository · API Docs · Examples · Changelog · Contributing
Installation
cargo add ratatui tui-prompts crossterm
Usage
Pick a prompt type, keep its state, and render it inside your UI.
Text Prompt
use Frame;
use ;
use ;
Store a prompt if its configuration is reused across frames.
use Frame;
use Rect;
use ;

See the text example for more details.
Select Prompt
SelectPrompt renders one focused option from an ordered list. Keep a [SelectState] beside
the prompt, render the prompt each frame, and route key events to the state. Up and Down move
the focused option, Enter completes the prompt, and Escape or Ctrl+C aborts it.
use Cow;
use KeyEvent;
use Frame;
use Rect;
use ;
See the select example for an interactive selection flow.
Soft Wrapping
Text is automatically character wrapped to fit in the render area.

See the multi line example for more details.
Features
- Text prompt
- Password prompt
- Invisible prompt
- Readline / emacs style Key Bindings
- Crossterm backend
- Soft wrapping single lines
- Multi-line input
- Scrolling
- More prompt types:
- Number
- Confirm
- List
- Toggle
- Select
- Multi-select
- Autocomplete
- Autocomplete multi-select
- Date
- Bracketed paste
- Validation
- Default initial value
- Custom style
- Themes
- Custom formatting
- Backend agnostic keyboard event handling
- Customizable key bindings
- Handle more advanced multi-key bindings e.g.
^[band^[f - Prompt chaining
Key Bindings
| Key | Action |
|---|---|
| Home, Ctrl+A | Move cursor to beginning of line |
| End, Ctrl+E | Move cursor to end of line |
| Left, Ctrl+B | Move cursor one character left |
| Right, Ctrl+F | Move cursor one character right |
| Backspace (Delete on Mac), Ctrl+H | Delete character before cursor |
| Delete (Fn+Delete on Mac), Ctrl+D | Delete character at cursor |
| Ctrl+K | Delete all characters from the cursor to the end of line |
| Ctrl+U | Delete the entire line |
| Up, Down | Move the focused select option |
| Enter | Complete the prompt |
| Escape, Ctrl+C | Abort the prompt |
More widgets
For the full suite of widgets, see tui-widgets.
License
Copyright (c) Josh McKinney
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
See CONTRIBUTING.md.