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 MenuState ExecuteCommand(int index) { switch ((Command)index) { case Command.Write: TextArea.Write(); Reply.Content = TextArea.Lines.ToList(); return(MenuState.AddReply); case Command.Submit: var replyAdded = PostService.TrySaveReply(Reply, PostView.PostId); if (!replyAdded) { Error = true; return(MenuState.Rerender); } return(MenuState.ReplyAdded); case Command.Back: ForumViewEngine.ResetBuffer(); return(MenuState.Back); } throw new InvalidCommandException(); }
public Engine() { this.forumViewer = new ForumViewEngine(); this.controllers = InitializeControllers(); this.menuController = new MenuController(this.controllers, forumViewer); }
public MenuState ExecuteCommand(int index) { switch ((Command)index) { case Command.Write: this.TextArea.Write(); this.Reply.Content = this.TextArea .Lines.ToList(); return(MenuState.AddReply); case Command.Submit: bool isReplyAdded = PostService.TryAddReply(this.Post.PostId, this.Reply); if (!isReplyAdded) { this.Error = true; return(MenuState.Rerender); } return(MenuState.ReplyAdded); case Command.Back: ForumViewEngine.ResetBuffer(); return(MenuState.Back); } throw new InvalidCommandException(); }
private void SetBuffer() { int totalLines = 24 + this.Post.Content.Count; if (totalLines > 30) { ForumViewEngine.SetBufferHeight(totalLines); } }
public MenuController(IEnumerable <IController> controllers, ForumViewEngine forumViewer) { this.controllers = controllers.ToArray(); this.forumViewer = forumViewer; this.InitializeControllerHistory(); this.currentOptionIndex = DEFAULT_INDEX; }
public MenuState ExecuteCommand(int index) { switch ((Command)index) { case Command.Back: ForumViewEngine.ResetBuffer(); return(MenuState.Back); case Command.AddReply: return(MenuState.AddReplyToPost); } throw new InvalidCommandException(); }
private void SetBuffer() { int totalLines = 10 + this.Post.Content.Count; foreach (var reply in this.Post.Replies) { totalLines += 2 + reply.Content.Count; } if (totalLines > 30) { ForumViewEngine.SetBufferHeight(totalLines); } }
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); }
public void ReadCategory() { Post.Category = ForumViewEngine.ReadRow(); ForumViewEngine.HideCursor(); }
public void ReadTitle() { Post.Title = ForumViewEngine.ReadRow(); ForumViewEngine.HideCursor(); }
public void ReadUsername() { this.Username = ForumViewEngine.ReadRow(); ForumViewEngine.HideCursor(); }
public void ReadPassword() { this.Password = ForumViewEngine.ReadRow(); ForumViewEngine.HideCursor(); }
private void ReadCategory() { this.Post.Category = ForumViewEngine.ReadRow(); ForumViewEngine.HideCursor(); }
private void ReadTitle() { this.Post.Title = ForumViewEngine.ReadRow(); ForumViewEngine.HideCursor(); }