console_engine/
lib.rs

1pub mod f_print {
2    use std::io::{self, Write};
3    use std::thread;
4    use std::time;
5
6    // prints a timed message to the console with a new line
7    pub fn println_timed(message: &str, time: time::Duration) {
8        print_timed(message, time);
9        new_line();
10    }
11
12    // prints a timed message to the console without a new line
13    pub fn print_timed(message: &str, time: time::Duration) {
14        for c in message.chars() {
15            print!("{}", c);
16            io::stdout().flush().unwrap();
17            thread::sleep(time);
18        }
19    }
20
21    // prints a message to the console with a new line
22    pub fn println(message: &str) {
23        print(message);
24        new_line();
25    }
26
27    // prints a message to the console without a new line
28    pub fn print(message: &str) {
29        print!("{}", message);
30        io::stdout().flush().unwrap();
31    }
32
33    // prints a blank line to the console
34    pub fn new_line() {
35        println!();
36    }
37}
38
39pub mod f_list {
40    use std::fmt;
41    use std::io::{self, Write};
42
43    pub struct List<T: fmt::Display> {
44        items: Vec<T>,
45    }
46
47    impl<T: fmt::Display> List<T> {
48        pub fn new() -> List<T> {
49            List { items: Vec::new() }
50        }
51
52        pub fn from(items: Vec<T>) -> List<T> {
53            List { items: items }
54        }
55
56        pub fn add_item(&mut self, item: T) {
57            self.items.push(item);
58        }
59
60        pub fn display(&self) {
61            for item in self.items.iter() {
62                println!("{}", item);
63            }
64        }
65
66        pub fn display_ordered(&self) {
67            for (x, item) in self.items.iter().enumerate() {
68                print!("[{}]: ", x + 1);
69                io::stdout().flush().unwrap();
70                println!("{}", item);
71            }
72        }
73    }
74}
75
76pub mod f_input {
77    use std::io;
78
79    // get untrimmed input from console
80    pub fn get_input() -> String {
81        let mut input = String::new();
82        io::stdin().read_line(&mut input).unwrap();
83        input
84    }
85
86    // get trimmed input from console
87    pub fn get_input_trimmed() -> String {
88        String::from(get_input().trim())
89    }
90}