fix for issue #49 by exiting if too many wrong menu input given

> 40 for now
This commit is contained in:
Vishal
2022-12-26 18:44:58 +05:30
parent 43b7e285ef
commit 0959c5019c
4 changed files with 28 additions and 2 deletions

View File

@@ -448,6 +448,8 @@ int showMenu(List<String> menuOptions, String menuName, [String menuInfo = ""])
if( valueOption >= 1 && valueOption <= menuOptions.length) {
reAdjustAlignment(); // in case user has changed alignment
print('You picked: $valueOption');
// reset this
gInvalidInputCount = 0;
return valueOption;
}
}
@@ -458,6 +460,13 @@ int showMenu(List<String> menuOptions, String menuName, [String menuInfo = ""])
}
}
printWarning("\nInvalid option. Kindly try again. The valid options are from 1 to ${menuOptions.length}");
gInvalidInputCount++;
if( gInvalidInputCount > gMaxInValidInputAccepted) {
printWarning("The program has received an invalid input more than $gMaxInValidInputAccepted. There seems to be some problem etc, so exiting");
exit(0);
//programExit();
}
}
}
@@ -1576,3 +1585,12 @@ Future<void> mainMenuUi(Store node) async {
} // end while
} // end mainMenuUi()
Future<void> programExit([String message= ""]) async {
if( gEventsFilename != "") {
await gStore?.writeEventsToFile(gEventsFilename);
}
print("In programexit");
exit(0);
}