Exemple #1
0
        public static (bool exit, WalletBackend wallet) SelectionScreen()
        {
            while (true)
            {
                LaunchAction action = GetAction();

                if (action == LaunchAction.Exit)
                {
                    return(true, null);
                }

                /* Get the walletbackend, or an error. On error, return
                 * to selection screen. */
                switch (LaunchWallet.HandleAction(action))
                {
                case ILeft <Error> error:
                {
                    RedMsg.WriteLine(
                        error.Value.errorMessage
                        );

                    YellowMsg.WriteLine("Returning to selection screen.\n");

                    continue;
                }

                case IRight <WalletBackend> wallet:
                {
                    return(false, wallet.Value);
                }
                }
            }
        }
Exemple #2
0
        /* printableCommands = the commands to print on bad input.
         * availableCommands = the commands that the inputted string is
         *                     checked against.
         *
         * For example, we print basic commands, but can input both basic
         * and advanced commands */
        private static string ParseCommand(
            IEnumerable <Command> printableCommands,
            IEnumerable <Command> availableCommands,
            string prompt)
        {
            string selection = null;

            while (true)
            {
                /* Write the prompt message */
                YellowMsg.Write(prompt);

                selection = Console.ReadLine().ToLower();

                /* \n == no-op */
                if (selection == "")
                {
                    continue;
                }

                /* Check if they entered a command or an number */
                if (int.TryParse(selection, out int selectionNum))
                {
                    /* We print 1, 2, 3, 4 etc to be user friendly but we want
                     * to access it with 0 indexing */
                    selectionNum--;

                    if (selectionNum < 0 ||
                        selectionNum >= availableCommands.Count())
                    {
                        RedMsg.Write("Bad input, expected a command " +
                                     "name, or number from ");
                        YellowMsg.Write("1 ");
                        RedMsg.Write("to ");
                        YellowMsg.WriteLine(availableCommands.Count().ToString());

                        PrintCommands(printableCommands);

                        continue;
                    }

                    /* Set the selection to the command name chosen via
                     * the previously printed numbers */
                    selection = availableCommands.ElementAt(selectionNum)
                                .commandName;
                }
                else
                {
                    /* Does the inputted command exist? */
                    if (!availableCommands.Any(c => c.commandName == selection))
                    {
                        Console.Write("Unknown command: ");
                        RedMsg.Write($"{selection}\n");

                        PrintCommands(printableCommands);

                        continue;
                    }
                }

                return(selection);
            }
        }
 private static bool Exit(WalletBackend wallet)
 {
     YellowMsg.WriteLine("Saving wallet and shutting down...");
     wallet.Save();
     return(true);
 }
 private static void Save(WalletBackend wallet)
 {
     YellowMsg.WriteLine("Saving...");
     wallet.Save();
     YellowMsg.WriteLine("Saved!");
 }
Exemple #5
0
 /* Writes out the coin name, version, and wallet name */
 private static void StartupMsg()
 {
     YellowMsg.WriteLine($"{Globals.coinName} {Globals.version} "
                         + $"{Globals.CLIWalletName}");
 }