コード例 #1
0
ファイル: MessageForm.cs プロジェクト: geo-xiros/Individual
        private void View()
        {
            ShowForm();
            Console.CursorVisible = false;

            Dictionary <ConsoleKey, Action> keyChoices = new Dictionary <ConsoleKey, Action>()
            {
                { ConsoleKey.Escape, () => { } }
            };

            if (HasPermissionTo(_RealLoggedUser.CanEdit))
            {
                ColoredConsole.Write("  [Enter] => Edit", 1, LastTextBoxY + 2, ConsoleColor.DarkGray);
                keyChoices.Add(ConsoleKey.Enter, FillForm);
            }

            if (HasPermissionTo(_RealLoggedUser.CanDelete))
            {
                ColoredConsole.Write(" [Delete] => Delete", 1, LastTextBoxY + 3, ConsoleColor.DarkGray);
                keyChoices.Add(ConsoleKey.Delete, AskAndDelete);
            }

            ReadKey <Action> readKey = new ReadKey <Action>(keyChoices);

            readKey.GetKey()();
        }
コード例 #2
0
        private static void AlertInBox(string message, ConsoleColor color, int timeout)
        {
            if (message.Length == 0)
            {
                return;
            }
            message = message.Replace("\r\n", "");

            if (message.Length > 80)
            {
                message = message.Substring(0, 80) + "...";
            }
            int x = Console.WindowWidth / 2 - message.Length / 2;
            int y = Console.WindowHeight / 3;

            Console.ResetColor();
            Console.Clear();
            ColoredConsole.Write(new string(' ', message.Length + 4), x - 2, y - 1, consoleBackColor: color);
            ColoredConsole.Write(new string(' ', message.Length + 4), x - 2, y, consoleBackColor: color);
            ColoredConsole.Write(new string(' ', message.Length + 4), x - 2, y + 1, consoleBackColor: color);
            ColoredConsole.Write(message, x, y, ConsoleColor.White);

            Console.ResetColor();
            System.Threading.Thread.Sleep(timeout);
        }
コード例 #3
0
ファイル: ListMenu.cs プロジェクト: geo-xiros/Individual
        private void Show()
        {
            int totalpages  = (_allMenuChoices.Count() / _MaxItemsPerPage) + 1;
            int currentPage = (_menuSkip / _MaxItemsPerPage) + 1;

            Console.CursorVisible = false;
            Console.ResetColor();
            Console.Clear();
            if (totalpages > 1)
            {
                ColoredConsole.Write(string.Format("{0," + (Console.WindowWidth - 1) + "}\r", $"Page [{currentPage}/{totalpages}]"), ConsoleColor.Yellow);
            }
            ColoredConsole.WriteLine($"{_menu}", ConsoleColor.Yellow);
            ColoredConsole.Write(new string('\x2500', Console.WindowWidth), ConsoleColor.White);
            ColoredConsole.WriteLine(_titles, ConsoleColor.White);
            ColoredConsole.Write(new string('\x2500', Console.WindowWidth), ConsoleColor.White);

            for (int i = 0; i < _menuChoices.Count; i++)
            {
                string aa = (i + 1).ToString() + ' ';
                Console.WriteLine($"{aa,3}{_menuChoices[i].Value}");
            }

            ColoredConsole.Write(new string('\x2500', Console.WindowWidth), ConsoleColor.White);


            ColoredConsole.Write(string.Format("{0," + (Console.WindowWidth - 1) + "}\r", $"Total List Rows : {_allMenuChoices.Count()} "), ConsoleColor.Green);
            ColoredConsole.WriteLine($"      [Esc] => Back", ConsoleColor.DarkGray);
            if (totalpages > 1)
            {
                ColoredConsole.WriteLine($"  [Page Up] => Previous Page\n[Page Down] => Next Page", ConsoleColor.DarkGray);
            }
        }
コード例 #4
0
        public static void Footer(string message)
        {
            int x = Console.WindowWidth / 2 - message.Length / 2;
            int y = Console.WindowHeight - 1;

            ColoredConsole.Write(message, x, y, ConsoleColor.Yellow);
            Console.ResetColor();
        }
コード例 #5
0
ファイル: MessageBox.cs プロジェクト: geo-xiros/Individual
        static private void ShowMessageInBox(string message)
        {
            int x = Console.WindowWidth / 2 - message.Length / 2;
            int y = Console.WindowHeight / 3;

            ColoredConsole.Write($"\x250C{new string('\x2500', message.Length + 2)}\x2510", x - 2, y - 1, ConsoleColor.White);
            ColoredConsole.Write($"\x2502{new string(' ', message.Length + 2)}\x2502", x - 2, y, ConsoleColor.White);
            ColoredConsole.Write($"\x2514{new string('\x2500', message.Length + 2)}\x2518", x - 2, y + 1, ConsoleColor.White);
            ColoredConsole.Write($"{message}", x, y, ConsoleColor.Green);
        }
コード例 #6
0
ファイル: TextBox.cs プロジェクト: geo-xiros/Individual
        public void Show(bool focused = false)
        {
            ConsoleColor backColor = focused ? ConsoleColor.Blue : ConsoleColor.Black;

            ColoredConsole.Write($"{Label}:", _labelX, _y, ConsoleColor.White);
            ColoredConsole.Write(new string(' ', _maxLength), _textX, _y, consoleBackColor: backColor);

            if (_passwordChar == char.MinValue || _text == null)
            {
                ColoredConsole.Write(_text, _textX, _y, ConsoleColor.DarkGray, backColor);
            }
            else
            {
                ColoredConsole.Write(new string(_passwordChar, _text.Length), _textX, _y, ConsoleColor.DarkGray, backColor);
            }
        }
コード例 #7
0
ファイル: Form.cs プロジェクト: geo-xiros/Individual
        protected void ShowForm()
        {
            Console.ResetColor();
            Console.Clear();
            ColoredConsole.WriteLine($"{Title}\n", ConsoleColor.Yellow);
            ColoredConsole.Write(new string('\x2500', Console.WindowWidth), 0, 1, ConsoleColor.White);
            Console.CursorVisible = true;

            int maxLabelLength = TextBoxes.Max(t => t.Value.Label.Length);

            foreach (var textbox in TextBoxes.Values)
            {
                textbox.Label = textbox.Label.PadLeft(maxLabelLength);
                textbox.Show();
            }
            ColoredConsole.Write(new string('\x2500', Console.WindowWidth), 0, LastTextBoxY, ConsoleColor.White);
            ColoredConsole.Write("    [Esc] => Back", 1, LastTextBoxY + 1, ConsoleColor.DarkGray);
        }
コード例 #8
0
ファイル: AccountForm.cs プロジェクト: geo-xiros/Individual
        private void View()
        {
            ShowForm();
            ColoredConsole.Write("  [Enter] => Edit", 1, LastTextBoxY + 2, ConsoleColor.DarkGray);
            ColoredConsole.Write(" [Delete] => Delete", 1, LastTextBoxY + 3, ConsoleColor.DarkGray);

            Console.CursorVisible = false;

            ReadKey <Action> readKey = new ReadKey <Action>(
                new Dictionary <ConsoleKey, Action>()
            {
                { ConsoleKey.Enter, FillForm },
                { ConsoleKey.Delete, AskAndDelete },
                { ConsoleKey.Escape, () => { } },
            });

            readKey.GetKey()();
        }
コード例 #9
0
 public void Write(string message, int x, int y, ConsoleColor consoleForeColor = ConsoleColor.White, ConsoleColor consoleBackColor = ConsoleColor.Black)
 {
     Console.SetCursorPosition(x, y);
     ColoredConsole.Write(message, consoleForeColor, consoleBackColor);
     Console.SetCursorPosition(x, y);
 }
コード例 #10
0
ファイル: TextBox.cs プロジェクト: geo-xiros/Individual
        private string ReadLine()
        {
            StringBuilder  buffer         = new StringBuilder();
            bool           _clearOldValue = _text?.Length != 0;
            ConsoleKeyInfo info;

            Console.BackgroundColor = ConsoleColor.Blue;
            Console.ForegroundColor = ConsoleColor.White;
            do
            {
                info = Console.ReadKey(true);

                switch (info.Key)
                {
                case ConsoleKey.Enter:
                    if ((buffer.Length == 0) && (_clearOldValue))
                    {
                        buffer.Append(_text);
                    }
                    break;

                case ConsoleKey.LeftArrow:
                case ConsoleKey.RightArrow:
                case ConsoleKey.DownArrow:
                case ConsoleKey.UpArrow:
                case ConsoleKey.Tab:
                case ConsoleKey.PageDown:
                case ConsoleKey.PageUp:
                case ConsoleKey.Escape:
                    break;

                case ConsoleKey.Backspace:
                    if (buffer.Length > 0)
                    {
                        Console.Write("\b");
                        Console.Write(" ");
                        Console.Write("\b");
                        buffer.Remove(buffer.Length - 1, 1);
                    }
                    break;

                default:
                    if (_clearOldValue)
                    {
                        ColoredConsole.Write(new string(' ', _maxLength), _textX, _y);
                        _clearOldValue = false;
                    }
                    if (_ValidationError != null)
                    {
                        ValidationError  = new string(' ', _ValidationError.Length);
                        _ValidationError = null;
                    }
                    if (buffer.Length < _maxLength)
                    {
                        if (_passwordChar == 0)
                        {
                            Console.Write(info.KeyChar);
                        }
                        else
                        {
                            Console.Write(_passwordChar);
                        }
                        buffer.Append(info.KeyChar);
                    }
                    break;
                }
            } while (info.Key != ConsoleKey.Enter && info.Key != ConsoleKey.Escape);

            _pressedEnter = info.Key == ConsoleKey.Enter;
            EscapePressed = info.Key == ConsoleKey.Escape;

            return(buffer.ToString());
        }