Skip to content

Instantly share code, notes, and snippets.

@kimitoboku
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimitoboku/bd3d7dba06ab0ad134a6 to your computer and use it in GitHub Desktop.
Save kimitoboku/bd3d7dba06ab0ad134a6 to your computer and use it in GitHub Desktop.
更新
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