Last active
August 29, 2015 14:27
-
-
Save kimitoboku/bd3d7dba06ab0ad134a6 to your computer and use it in GitHub Desktop.
更新
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(string s; list){ | |
if(cmp(input,toLower(s)) == 0){ | |
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(cmp(toLower(chop(buf)),"yes") == 0){ | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment