keyezinput/
lib.rs

1//! Fast and easy way to ask keyboard user input
2//! 
3//! Provides an easy way to take user input from the std buffer
4
5// The module :)
6pub mod input{
7    use std::io::{self, Write};
8
9    // This function takes all buffer line. It return a String object.
10    pub fn input_line(msg: &str) -> String {
11        let stdin = io::stdin();
12        let mut stdout = io::stdout();
13    
14        let mut input = String::new();
15    
16        print!("{}", msg);
17    
18        match stdout.flush(){
19            Ok(_) => {
20                match stdin.read_line(&mut input){
21                    Ok(_)=>{}
22                    Err(e) => panic!("Oops! An error ocurrs in read_line::lib.rs::15 : {}", e)
23                };
24            }
25            Err(e) => panic!("Oops! An error ocurrs in flush::lib.rs::15 : {}", e)
26        }
27        
28    
29        return clean_input(&mut input);
30    }
31
32    pub fn clean_input(input: &mut String) -> String {
33        let mut clear_str: String = String::new();
34
35        for i in 0..input.len()-2 {
36            clear_str.push(input.chars().nth(i).unwrap());
37        }
38        
39        return clear_str;
40    }
41}