1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
/// Handles the input from various sources, such as stdin or a file

use std::io::{ self, BufRead, Error, Read };

pub fn stdin() -> io::Result<Vec<String>> {
    let stdin = io::stdin();
    let mut buffer: Vec<String> = Vec::new();
    let lines = stdin.lock().lines();
    for line in lines {
        if line.as_ref().unwrap() == ":quit" { break }
        buffer.push(line.unwrap());
    }
    Ok(buffer)
}

pub fn stdin_byte() -> Result<Vec<u8>, Error> {
    let mut stdin = io::stdin();
    let mut buffer = vec![0u8; 1024];
    stdin.read_to_end(&mut buffer)?;
    Ok(buffer)
}