Example #1
0
        public static NumericDialogChoice ShowNumericDialog(List <string> message, List <string> options)
        {
            int    choice   = -1;
            int    attempts = 0;
            string res      = string.Empty;

            while (!validChoice(res, options))
            {
                if (attempts > 0)
                {
                    Console.WriteLine("    - Invalid Selection");
                }
                BoxedLine.DrawBoxedLine(message.ToArray(), 75, ConsoleColor.Black, ConsoleColor.White, true, true, true);
                //Console.WriteLine(message);
                //Console.WriteLine("");
                List <string> msg = new List <string>();
                msg.Add("");
                for (int i = 0; i < options.Count; i++)
                {
                    msg.Add((i + 1).ToString() + ". " + options[i]);
                    //Console.WriteLine((i + 1).ToString() + ". " + options[i]);
                }
                msg.Add("");
                BoxedLine.DrawBoxedLine(msg.ToArray(), 75, ConsoleColor.Black, ConsoleColor.White, false, false, true);
                //Console.WriteLine("");
                Console.Write(" => ");
                res = Console.ReadLine();
                Console.WriteLine("");
            }
            bool valid = Int32.TryParse(res, out choice);

            return(new NumericDialogChoice(choice, options[choice - 1]));
        }
Example #2
0
        public static void DrawBoxedLine(string[] text, int width, ConsoleColor backColor, ConsoleColor foreColor, bool centerText, bool drawTopBorder, bool drawBottomBorder)
        {
            int           rows     = text.Length;
            BoxedLine     box      = new BoxedLine(text, width, backColor, foreColor, drawTopBorder, drawBottomBorder);
            List <string> boxified = new List <string>();

            if (drawTopBorder)
            {
                string border = " ┌";

                for (int w = 0; w < box.boxWidth; w++)
                {
                    border += "─";
                }
                border += "┐ ";
                boxified.Add(border);
            }

            for (int i = 0; i < rows; i++)
            {
                string line = " │ ";
                if (text[i].Length < box.boxWidth)
                {
                    if (centerText)
                    {
                        int d = box.boxWidth - text[i].Length;
                        if (d % 2 != 0)
                        {
                            d--;
                        }
                        int p = d / 2;
                        for (int spc = p; spc > 0; spc--)
                        {
                            line += " ";
                        }
                        line += text[i];
                        for (int spc = p; spc > 0; spc--)
                        {
                            line += " ";
                        }
                    }
                    else
                    {
                        line += text[i];
                        for (int spc = box.boxWidth - (text[i].Length + 1); spc > 0; spc--)
                        {
                            line += " ";
                        }
                    }
                    line += "│ ";
                }
                else
                {
                    line += text[i] + " │ ";
                }
                boxified.Add(line);
            }

            if (drawBottomBorder)
            {
                string border = " └";
                for (int w = 0; w < box.boxWidth; w++)
                {
                    border += "─";
                }
                border += "┘ ";
                boxified.Add(border);
            }

            foreach (string s in boxified)
            {
                Console.BackgroundColor = box.backColor;
                Console.ForegroundColor = box.foreColor;
                Console.WriteLine(s);
            }
        }