tui-prompts
is a Rust crate that provides prompt widgets for the Ratatui crate. It allows for easy
creation of interactive command-line interfaces with various types of prompts. Inspired by
https://www.npmjs.com/package/prompts and various other prompt libraries.
Code
```rust struct App<'a> { usernamestate: TextState<'a>, passwordstate: TextState<'a>, invisible_state: TextState<'a>, }
impl<'a> App<'a> {
fn drawui
TextPrompt::from("Username")
.draw(frame, username_area, &mut self.username_state);
TextPrompt::from("Password")
.with_render_style(TextRenderStyle::Password)
.draw(frame, password_area, &mut self.password_state);
TextPrompt::from("Invisible")
.with_render_style(TextRenderStyle::Invisible)
.draw(frame, invisible_area, &mut self.invisible_state);
}
} ```
See the text example for more details.
Text is automatically character wrapped to fit in the render area.
See the multi line example for more details.
^[b
and ^[f
for start / end of lineshell
cargo add ratatui
cargo add tui-prompts
Or add the following to your Cargo.toml
file:
toml
[dependencies]
ratatui = "0.22.0"
tui-prompts = "0.2.0"
| 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 | Enter | Complete the prompt | Escape, Ctrl+C | Abort the prompt
Dual-licensed under Apache 2.0 or MIT.