mirror of
https://github.com/znc/znc.git
synced 2026-06-26 04:52:05 +02:00
Added default values for GetInput() and GetBoolInput()
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@204 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -223,9 +223,19 @@ char* CUtils::GetPass(const string& sPrompt) {
|
||||
return getpass("");
|
||||
}
|
||||
|
||||
bool CUtils::GetBoolInput(const string& sPrompt) {
|
||||
string sRet;
|
||||
GetInput(sPrompt + " [yes/no]", sRet);
|
||||
bool CUtils::GetBoolInput(const string& sPrompt, bool bDefault) {
|
||||
return CUtils::GetBoolInput(sPrompt, &bDefault);
|
||||
}
|
||||
|
||||
bool CUtils::GetBoolInput(const string& sPrompt, bool *pbDefault) {
|
||||
string sRet, sDefault;
|
||||
string sExtra = " (yes/no)";
|
||||
|
||||
if (pbDefault) {
|
||||
sDefault = (*pbDefault) ? "yes" : "no";
|
||||
}
|
||||
|
||||
GetInput(sPrompt + sExtra, sRet, sDefault);
|
||||
|
||||
if (strcasecmp(sRet.c_str(), "yes") == 0) {
|
||||
return true;
|
||||
@@ -233,21 +243,25 @@ bool CUtils::GetBoolInput(const string& sPrompt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return GetBoolInput(sPrompt);
|
||||
return GetBoolInput(sPrompt, pbDefault);
|
||||
}
|
||||
|
||||
bool CUtils::GetInput(const string& sPrompt, string& sRet) {
|
||||
PrintPrompt(sPrompt);
|
||||
bool CUtils::GetInput(const string& sPrompt, string& sRet, const string& sDefault) {
|
||||
string sExtra = (!sDefault.empty()) ? (" [" + sDefault + "]") : "";
|
||||
PrintPrompt(sPrompt + sExtra);
|
||||
char szBuf[1024];
|
||||
memset(szBuf, 0, 1024);
|
||||
fgets(szBuf, 1024, stdin);
|
||||
|
||||
sRet = szBuf;
|
||||
|
||||
if (CUtils::Right(sRet, 1) == "\n") {
|
||||
CUtils::RightChomp(sRet);
|
||||
}
|
||||
|
||||
if (sRet.empty()) {
|
||||
sRet = sDefault;
|
||||
}
|
||||
|
||||
return !sRet.empty();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user