Skip to content

Commit 4a93848

Browse files
committed
Added input()
1 parent 1e0e5fb commit 4a93848

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/console.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io::{stdin, stdout, Read, Write};
1+
use std::io::{stdin, stdout, BufRead, Read, Write};
22
use std::process::exit;
33
use ansi_term::Style;
44
use ansi_term::Color::{Red, Yellow, Green, Cyan, Blue, Purple};
@@ -99,6 +99,18 @@ pub fn confirm(message: impl Into<String>) -> bool {
9999
String::from_utf8_lossy(&ch) == "y"
100100
}
101101

102+
pub fn input(message: impl Into<String>) -> String {
103+
print!("{}", message.into());
104+
stdout().flush().expect("Failed to flush stdout.");
105+
106+
let stdin = std::io::stdin();
107+
let mut res = String::new();
108+
109+
stdin.lock().read_line(&mut res).expect("Failed to read stdin");
110+
111+
res
112+
}
113+
102114
pub fn confirm_or_exit(message: &str) {
103115
if !confirm(message) {
104116
println!("Cancelled");

0 commit comments

Comments
 (0)