mirror of
https://github.com/nushell/reedline.git
synced 2024-11-09 04:56:48 +03:00
A readline replacement written in Rust
ad33d8e0f3
* Add more support for vi * Fix doctests |
||
---|---|---|
.github/workflows | ||
assets/sample_docs | ||
src | ||
.gitignore | ||
Cargo.lock | ||
Cargo.toml | ||
LICENSE | ||
README.md | ||
TODO.txt |
A readline replacement written in Rust
Example (Simple REPL)
// Create a default reedline to handle user input
use reedline::{Reedline, DefaultPrompt, Signal};
let mut line_editor = Reedline::new();
let prompt = DefaultPrompt::default();
loop {
let sig = line_editor.read_line(&prompt).unwrap();
match sig {
Signal::CtrlD | Signal::CtrlC => {
line_editor.print_crlf().unwrap();
break;
}
Signal::Success(buffer) => {
// process `buffer`
println!("We processed: {}", buffer);
}
Signal::CtrlL => {
line_editor.clear_screen().unwrap();
}
}
}
Keybindings
// Configure reedline with custom keybindings
let mut keybindings = default_keybindings();
keybindings.add_binding(
KeyModifiers::ALT,
KeyCode::Char('m'),
vec![EditCommand::BackspaceWord],
);
let mut line_editor = Reedline::new()
.with_keybindings(keybindings);
History
// Create a reedline with history support, including history size limits
let mut line_editor = Reedline::new()
.with_history("history.txt", 5)?
Are we prompt yet? (Development status)
This crate is currently under active development in JT's live-coding streams. If you want to see a feature, jump by the streams, file an issue or contribute a PR!
- Basic unicode grapheme aware cursor editing.
- Configurable prompt
- Basic EMACS-style editing shortcuts.
- Advanced multiline unicode aware editing.
- Configurable keybindings.
- Basic system integration with clipboard or optional stored history file.
- Content aware highlighting or validation.
- Autocompletion.
For a more detailed roadmap check out TODO.txt.
Alternatives
For currently more mature Rust line editing check out: