internal void Write() { ForumViewEngine.DrawTextArea(this); ForumViewEngine.ShowCursor(); while (true) { ConsoleKeyInfo keyInfo = Console.ReadKey(true); ConsoleKey key = keyInfo.Key; if (key == ConsoleKey.Backspace) { this.Delete(); } else if (this.Text.Length == this.MaxLength || forbiddenCharacters.Contains(keyInfo.KeyChar)) { Console.Beep(415, 260); continue; } else if (key == ConsoleKey.Enter || key == ConsoleKey.Escape) { break; } else { this.AddCharacter(keyInfo.KeyChar); } } ForumViewEngine.HideCursor(); }
public void Delete() { if (this.textCursorPosition > 0) { string stringBefore = this.Text.Substring(0, this.textCursorPosition); string stringAfter = this.Text.Substring(this.textCursorPosition, this.Text.Length - textCursorPosition); stringBefore = stringBefore.Substring(0, stringBefore.Length - 1); this.Text = stringBefore + stringAfter; this.textCursorPosition--; ForumViewEngine.DrawTextArea(this); } this.lines = StringProcessor.Split(this.Text); }
public bool AddCharacter(char character) { if (this.Text.Length < this.MaxLength) { string stringBefore = this.Text.Substring(0, this.textCursorPosition); string stringAfter = this.Text.Substring(this.textCursorPosition, this.Text.Length - this.textCursorPosition); this.Text = stringBefore + character + stringAfter; this.textCursorPosition++; ForumViewEngine.DrawTextArea(this); return(true); } return(false); }