pub const fn with<E: Editor>(editor: E, prompt: &str) -> Prompt<'_, E> ⓘ
Expand description
Construct a new Prompt
with a custom editor
Examples found in repository?
examples/colors.rs (line 21)
20 21 22 23 24 25 26 27 28 29 30 31
fn main() {
let mut rainbow = pomprt::with(Rainbow, "><> ");
loop {
match rainbow.read() {
Ok(input) => println!("\x1b[37m{input}"),
Err(pomprt::Eof) => return println!("\x1b[31mctrl-d"),
Err(pomprt::Interrupt) => return println!("\x1b[31mctrl-c"),
Err(e) => return eprintln!("\x1b[31merror\x1b[m: {e}"),
}
}
}
More examples
examples/completion.rs (line 48)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut sh = pomprt::with(MiniShell, "% ");
loop {
let ok = match sh.read() {
Ok(input) => {
let mut args = input.split_ascii_whitespace();
if let Some(cmd) = args.next() {
Command::new(cmd).args(args).spawn()?.wait()?.success()
} else {
true
}
}
Err(pomprt::Interrupt) => false,
Err(pomprt::Eof) => return Ok(()),
Err(e) => Err(e)?,
};
sh.set_prompt(if ok { "% " } else { "! " });
}
}