treasurechest/cli/ui/menus/MainMenu.cs

66 lines
2.2 KiB
C#
Raw Permalink Normal View History

using System;
using treasurechest.STDIOWrapper;
using treasurechest;
namespace treasurechestCLI
{
internal class TreasureChestMenu{
private string language;
public TreasureChestMenu(){
language = translations.GetLanguage.language;
}
internal void showMenu(){
translations.Strings strings = new translations.Strings();
string[] mainMenuOptions = {strings.MAIN_MENU_ENCRYPT, strings.MAIN_MENU_DECRYPT, strings.MAIN_MENU_KEYRING, strings.EXIT};
STDIO.O(strings.WELCOME);
int counter = 1;
int choice = 0;
int mainMenuOptionsSize = mainMenuOptions.Length;
while (choice != mainMenuOptions.Length){
foreach (string option in mainMenuOptions){
STDIO.O(counter.ToString() + ". " + option);
counter += 1;
}
try{
choice = Int32.Parse(System.Console.ReadLine());
}
catch (System.OverflowException){
// User being silly with input
STDIO.O(strings.MAIN_MENU_SELECT_INTEGER);
counter = 1;
}
catch(System.FormatException){
// Too lazy to check strings, force them to use int from menu which is faster anyway
STDIO.O(strings.MAIN_MENU_SELECT_INTEGER);
counter = 1;
}
catch(System.ArgumentNullException){
// Can happen when stream closes (e.g. ctrl-d)
// since menu is intended to be directly human interfaced, user probably wants to exit
choice = mainMenuOptionsSize;
}
2020-05-23 09:51:17 +00:00
if (choice == 1){
EncryptMenu.enterMenu(strings);
}
2020-06-02 07:57:58 +00:00
else if (choice == 3){
new KeyRingMenu();
}
2020-05-23 09:51:17 +00:00
else if (choice == mainMenuOptionsSize){
// Exit is final option
break;
}
else{
STDIO.O(strings.INVALID_OPTION);
}
counter = 1;
}
}
}
}