-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathcontinuation_prompt.rs
37 lines (34 loc) · 1018 Bytes
/
continuation_prompt.rs
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
31
32
33
34
35
36
37
use rustyline::validate::MatchingBracketValidator;
use rustyline::{Cmd, Editor, EventHandler, KeyCode, KeyEvent, Modifiers, Result, highlight::Highlighter};
use rustyline::{Completer, Helper, Hinter, Validator};
use std::borrow::Cow::{self, Borrowed};
#[derive(Completer, Helper, Hinter, Validator)]
struct InputValidator {
#[rustyline(Validator)]
brackets: MatchingBracketValidator,
}
impl Highlighter for InputValidator {
fn continuation_prompt<'p, 'b>(
&self,
prompt: &'p str,
default: bool,
) -> Option<Cow<'b, str>> {
Some(Borrowed(".... "))
}
}
fn main() -> Result<()> {
let h = InputValidator {
brackets: MatchingBracketValidator::new(),
};
let mut rl = Editor::new()?;
rl.set_helper(Some(h));
rl.bind_sequence(
KeyEvent(KeyCode::Char('s'), Modifiers::CTRL),
EventHandler::Simple(Cmd::Newline),
);
loop {
let input = rl.readline(">>>> ")?;
println!("Input:\n{input}");
}
Ok(())
}