1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::io;
use std::io::Write;
pub mod shell;
static mut HOME: String = String::new();
pub fn init() {
let homedir = home::home_dir()
.unwrap()
.into_os_string()
.into_string()
.unwrap();
unsafe {
HOME = String::from(homedir + "/.rustmetos");
}
}
pub fn home() -> &'static str {
unsafe { &HOME }
}
pub fn input(prompt: &str) -> String {
print!("{}", prompt);
io::stdout()
.flush()
.expect("Unable to flush the stdout stream");
let mut buffer = String::new();
io::stdin()
.read_line(&mut buffer)
.expect("Unable to read into the buffer");
trim_newline(&mut buffer);
buffer
}
fn trim_newline(s: &mut String) {
if s.ends_with('\n') {
s.pop();
if s.ends_with('\r') {
s.pop();
}
}
}