multiline_input
Terminal multiline input with rich editing capabilities
Scope
Responsibility:
- Terminal multiline input widget with rich editing capabilities
- ENTER to submit, CTRL+ENTER for newlines (optimized for AI assistants)
- Raw terminal mode with visual feedback and validation
- Cross-platform support (Linux, macOS, Windows)
In Scope:
- Multiline text input widget
- Line editing (cursor movement, backspace, delete)
- Terminal manipulation (raw mode, key event capture)
- Visual feedback (line numbers, status line, colors)
- Validation (min/max length, custom validators)
- Builder API for configuration
- Pre-filled text editing
- Key bindings (ENTER, CTRL+ENTER, ESC, arrows, Home, End)
- Cross-platform terminal support
Out of Scope:
- ❌ Wizard framework → delegated to
terminal_wizardcrate - ❌ CLI applications → individual binaries use this as library
- ❌ Scrolling for large texts → future work
- ❌ Undo/redo → future work
- ❌ Clipboard integration → future work
Features
- ENTER to submit input
- CTRL+ENTER to insert newline (multiline support)
- Rich line editing (cursor movement, backspace, delete)
- Visual feedback (line numbers, status line, colors)
- Validation (min/max length, custom validators)
- Cross-platform (Linux, macOS, Windows)
- Zero-config defaults
Quick Start
use collect;
Key Bindings
| Key | Action |
|---|---|
| ENTER | Submit input and return |
| CTRL+ENTER | Insert newline |
| ESC | Cancel (returns None) |
| CTRL+C | Cancel (returns None) |
| CTRL+D | Submit (alternative to ENTER) |
| Backspace | Delete character before cursor |
| Delete | Delete character at cursor |
| ←/→ | Move cursor left/right |
| ↑/↓ | Move cursor up/down (between lines) |
| Home | Move to start of current line |
| End | Move to end of current line |
| CTRL+Home | Move to start of text |
| CTRL+End | Move to end of text |
Advanced Usage
With Builder Pattern
use Builder;
let editor = new
.prompt
.min_length
.max_length
.show_line_numbers
.show_status
.color
.build;
match editor.collect
With Validation
use Builder;
let editor = new
.prompt
.validator
.build;
match editor.collect
Pre-filled Text
use Builder;
let editor = new
.prompt
.initial_text
.show_line_numbers
.build;
match editor.collect
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
prompt |
&str |
"" |
Prompt message to display |
allow_empty |
bool |
true |
Allow empty input |
min_length |
Option<usize> |
None |
Minimum text length |
max_length |
Option<usize> |
None |
Maximum text length |
validator |
Fn(&str) -> Result<(), String> |
None |
Custom validation function |
initial_text |
Option<String> |
None |
Pre-filled text |
placeholder |
Option<String> |
None |
Placeholder text when empty |
show_line_numbers |
bool |
false |
Display line numbers |
show_status |
bool |
false |
Display status line (line/col/chars) |
show_char_count |
bool |
false |
Display character count |
color |
bool |
true |
Enable colored output |
Examples
See examples/ directory for more usage examples:
basic_usage.rs- Simple input collectionwith_validation.rs- Custom validationwith_config.rs- Full configuration demopre_filled.rs- Edit existing text
Run examples:
How It Works
- Enters raw terminal mode to capture individual key events
- Parses key combinations (ENTER, CTRL+ENTER, arrows, etc.)
- Updates text buffer with insertions/deletions
- Renders to screen with visual feedback
- Returns collected text on ENTER or None on ESC/CTRL+C
Platform Support
- ✅ Linux: Full support (all terminals)
- ✅ macOS: Full support (Terminal.app, iTerm2)
- ⚠️ Windows:
- Windows Terminal: Full support
- cmd.exe: Limited (CTRL+ENTER may not work)
- ConEmu: Full support
Implementation Status
- Core input collection
- Key event handling (ENTER, CTRL+ENTER, ESC, arrows)
- Text buffer with cursor management
- Basic rendering
- Builder API
- Validation (min/max, custom)
- Visual enhancements (line numbers, status, colors)
- Scrolling for large texts
- Undo/redo
- Clipboard integration
Documentation
For complete specification and implementation details, see spec.md.
For API documentation: cargo doc --open
Testing
# Run tests
# Run with coverage
Contributing
Contributions welcome! Please:
- Read spec.md for architecture details
- Write tests for new features
- Follow existing code style
- Update documentation
License
MIT License - see LICENSE for details
Related Projects
Difference: multiline_input focuses specifically on multiline text collection with ENTER to submit and CTRL+ENTER for newlines, optimized for AI assistant integration and commit message editing.