use rustyline::error::ReadlineError;
use rustyline::Editor;
use std::process::exit;
extern crate v_htmlescape;
use v_htmlescape::escape;
pub fn prompt(given_prompt: &str) -> String {
let mut editor = Editor::<()>::new();
let readline = editor.readline(&given_prompt);
match readline {
Ok(line) => {
line
},
Err(ReadlineError::Interrupted) => {
exit(0)
},
Err(ReadlineError::Eof) => {
exit(1)
}
Err(err) => {
println!("Error: {:?}", err);
exit(1)
}
}
}
pub fn edit_prompt(prompt: &str, value: &str) -> String {
let mut editor = Editor::<()>::new();
let readline = editor.readline_with_initial(prompt, (value, ""));
match readline {
Ok(line) => {
line
},
Err(ReadlineError::Interrupted) => {
exit(0)
},
Err(ReadlineError::Eof) => {
exit(1)
}
Err(err) => {
println!("Error: {:?}", err);
exit(1)
}
}
}
pub fn filter_prompt(given_prompt: &str) -> String {
let filtered_input: String = prompt(given_prompt);
escape(&filtered_input).to_string()
}