-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrompts.d
54 lines (44 loc) · 893 Bytes
/
Prompts.d
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
50
51
52
53
54
module Prompts;
extern (C) {
char *getpass(const char *);
}
import std.stdio;
import std.string;
import std.conv;
string Prompt(string msg){
write(msg," : ");
string buf = readln();
return chop(buf);
}
string Password(string msg){
auto output = format("%s : ",msg);
auto buf = getpass(toStringz(output));
return to!string(buf);
}
string Choose(string msg,string[] list,string defa){
write(msg," ", list ," (",defa,"): ");
string buf = readln();
string input = toLower(chop(buf));
foreach(s; list){
if(input == toLower(s)){
return s;
}
}
return defa;
}
bool YN(string msg){
write(msg," [Y/N]: ");
string buf = readln();
if(toLower(buf[0]) == 'y'){
return true;
}
return false;
}
bool YesNo(string msg){
write(msg," [Yes/No]: ");
string buf = readln();
if(toLower(chop(buf)) == "yes"){
return true;
}
return false;
}