internal static void RunLog() { while (true) { try { WriteCurrentText(true); ConsoleKeyInfo cki = Console.ReadKey(true); lock (lock_KeyObject) { switch (cki.Key) { case ConsoleKey.Enter: string text = currentText; if (text.Length > 0) { if (previousTexts.Count == MaxPreviousTexts) { previousTexts.RemoveAt(previousTexts.Count - 1); } previousTexts.Insert(0, text); WriteNewLine(text); typedText.Clear(); currentText = string.Empty; cursorPos[0] = 0; if (!ServerOptions.ProcessCmd(text) && OnCommand != null) { OnCommand(text); } } previousIndex = -1; break; case ConsoleKey.Escape: typedText.Clear(); cursorPos[0] = 0; previousIndex = -1; break; case ConsoleKey.Backspace: if (cursorPos[0] > 0 && cursorPos[0] <= currentText.Length) { typedText.Remove(cursorPos[0] - 1, 1); cursorPos[0]--; } break; case ConsoleKey.Delete: if (cursorPos[0] >= 0 && cursorPos[0] < currentText.Length) { typedText.Remove(cursorPos[0], 1); } break; case ConsoleKey.UpArrow: if (previousTexts.Count > 0 && previousIndex < previousTexts.Count - 1) { previousIndex++; typedText.Clear(); typedText.Append(previousTexts[previousIndex]); cursorPos[0] = previousTexts[previousIndex].Length; } break; case ConsoleKey.DownArrow: if (previousIndex >= 0) { previousIndex--; } typedText.Clear(); if (previousIndex >= 0) { typedText.Append(previousTexts[previousIndex]); cursorPos[0] = previousTexts[previousIndex].Length; } else { cursorPos[0] = 0; } break; case ConsoleKey.LeftArrow: if (cursorPos[0] > 0) { cursorPos[0]--; } break; case ConsoleKey.RightArrow: if (cursorPos[0] < currentText.Length) { cursorPos[0]++; } break; default: if (cki.KeyChar != '\0') { typedText.Insert(cursorPos[0], cki.KeyChar); cursorPos[0]++; } break; } } } catch (Exception e) { Logger.LogError(e); } } }