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); }
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()); }