1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
use rustyline::highlight::MatchingBracketHighlighter;
use rustyline::validate::MatchingBracketValidator;
use rustyline::{Cmd, Editor, EventHandler, KeyCode, KeyEvent, Modifiers, Result};
use rustyline::{Completer, Helper, Highlighter, Hinter, Validator};
#[derive(Completer, Helper, Highlighter, Hinter, Validator)]
struct InputValidator {
#[rustyline(Validator)]
brackets: MatchingBracketValidator,
#[rustyline(Highlighter)]
highlighter: MatchingBracketHighlighter,
}
fn main() -> Result<()> {
let h = InputValidator {
brackets: MatchingBracketValidator::new(),
highlighter: MatchingBracketHighlighter::new(),
};
let mut rl = Editor::new()?;
rl.set_helper(Some(h));
rl.bind_sequence(
KeyEvent(KeyCode::Char('s'), Modifiers::CTRL),
EventHandler::Simple(Cmd::Newline),
);
let input = rl.readline("> ")?;
println!("Input: {input}");
Ok(())
}
|