editor

Function editor 

Source
pub fn editor(name: &str, message: &[u8]) -> Result<String>
Expand description

Ask the user to enter some text through their editor.

We’ll check the VISUAL environment variable, then EDITOR, and then finally default to vi. The message will be the initial contents of the file, and the result will be the final contents of the file, after the user has quit their editor.

On Windows, the editor defaults to notepad.

Examples found in repository?
examples/everything.rs (line 34)
5pub fn main() -> io::Result<()> {
6    // Messages.
7
8    quest::success("Operation successful!");
9    quest::error("Error: The compiler ate your laundry.");
10
11    // Choose
12
13    let choices = &["Well", "Brilliant", "Amazing"];
14    quest::ask("How are you today?\n");
15    let choice = quest::choose(Default::default(), choices)?;
16    println!("It's good to see that you're {}.\n", choices[choice].to_lowercase());
17
18    // Text
19
20    quest::ask("What's your name? ");
21    let name = quest::text()?;
22    println!("Hello, {}!\n", name);
23
24    // Password
25
26    quest::ask("Password: ");
27    let password = quest::password()?;
28    println!("Correct, the password is {}.\n", password);
29
30    // Editor
31
32    let name = "script.py";
33    let message = b"# Write a Python script.\n";
34    let script = quest::editor(name, message)?;
35
36    println!("Here's what you wrote. {{");
37    for line in script.lines() {
38        println!("    {}", line);
39    }
40    println!("}}\n");
41
42    // Yes-No
43
44    match loop {
45        quest::ask("Are you the one? [yN] ");
46        match quest::yesno(false)? {
47            Some(b) => break b,
48            None => (),
49        }
50    } {
51        true => println!("No, I AM THE ONE!"),
52        false => println!("I guess not."),
53    }
54
55    Ok(())
56}