public void AddOutputLine(string text) { // break the input text up into lines of the right size List <string> lines = Chunker.ChunkString(text, Console.WindowWidth); foreach (string line in lines) { OutputHistory.Enqueue(line); } LastLineToDisplay = OutputHistory.Count; Update(); }
// TODO: finish this new version of Update // Redraw the display within the console window without overflowing the buffer, so no scrolling happens public void Update() { Console.Clear(); // start the cursor in a place so that there's exactly enough room to print out all of the output from the int CursorRow = 0; Console.SetCursorPosition(0, CursorRow); // write output lines until the cursor is at 4th from the bottom line foreach (string line in OutputHistory.Slice(LastLineToDisplay - Console.WindowHeight + 4, LastLineToDisplay)) { SpecialWrite(line); CursorRow += 1; Console.SetCursorPosition(0, CursorRow); } Console.SetCursorPosition(0, Console.WindowHeight - 4); // draw the kMUD messages and the command in the bottom 4 lines Console.Write("\u2508\u2508\u2508kMUD (Kirk's MUD client)"); for (int i = 0; i < Console.WindowWidth - 27; i++) { Console.Write('\u2508'); } CursorRow += 1; Console.SetCursorPosition(0, Console.WindowHeight - 3); // write as much of the message as fits // TODO: make message area expand for larger messages? Console.Write(kMUDMessage.Substring(0, Math.Min(Console.WindowWidth, kMUDMessage.Length))); Console.SetCursorPosition(0, Console.WindowHeight - 2); for (int i = 0; i < Console.WindowWidth; i++) { Console.Write('\u2508'); } if (Echoing) { WriteCommand(); } else { // put the cursor there Console.SetCursorPosition(0, Console.WindowHeight - 1); } }