Example #1
0
        /// <summary>
        /// The main program loop, we loop until the user decides to exit the
        /// entire program or if an unrecoverable error would happen while the
        /// user is interacting with the program in various states.
        /// </summary>
        /// <returns>
        /// False, if the program should no longer continue running.
        /// </returns>
        public bool Loop()
        {
            // Initialize program to running.
            bool running = true;

            // Loop while the user has decided not to exit.
            while (running)
            {
                // Make sure we have a text ui instance
                if (tui != null)
                {
                    // Clear the screen buffer on each pass.
                    tui.ClearBuffer();

                    // Make sure our function pointer is not null before running the function.
                    if (updateDelegates[(int)currentState] != null)
                    {
                        // Run the function and return whether we should continue running the program.
                        running = updateDelegates[(int)currentState]();

                        // Our header is based on our current state.
                        tui.Header = " | " + currentState.ToString().Replace('_', ' ') + " | ";

                        // Clear the footer (most recent message).
                        tui.Footer = "";
                    }
                    else
                    {
                        // We probably should run the program while we have null function pointers.
                        running = false;
                    }
                }
                else
                {
                    // We can't run the program without a text ui instance.
                    running = false;
                }
            }
            return(running);
        }