internal void OnEnter() { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("> " + InputString); string inputString = InputString; InputString = string.Empty; OnInputText?.Invoke(inputString); RedrawInputLine(); }
internal void OnEnter() { ClearLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("> " + inputString); var strtext = inputString; inputString = ""; OnInputText?.Invoke(strtext); }
private static void OnEnter() { ConsoleWindow.ClearLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("> " + InputString); inputHistory.Add(InputString); inputHistoryIndex = inputHistory.Count; string inputString = InputString; InputString = string.Empty; inputCursorLeft = 0; InputRedraw(); OnInputText?.Invoke(inputString); }
public void Update() { if (!Valid) { return; } if (nextUpdate < Interface.Oxide.Now) { RedrawInputLine(); nextUpdate = Interface.Oxide.Now + 0.5f; } try { if (!Console.KeyAvailable) { return; } } catch (Exception) { return; } var consoleKeyInfo = Console.ReadKey(); if (consoleKeyInfo.Key != ConsoleKey.DownArrow && consoleKeyInfo.Key != ConsoleKey.UpArrow) { inputHistoryIndex = 0; } switch (consoleKeyInfo.Key) { case ConsoleKey.Enter: ClearLine(Interface.Oxide.Config.Console.ShowStatusBar ? StatusTextLeft.Length : 1); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(string.Concat("> ", inputString)); inputHistory.Insert(0, inputString); if (inputHistory.Count > 50) { inputHistory.RemoveRange(50, inputHistory.Count - 50); } var str = inputString; inputString = string.Empty; OnInputText?.Invoke(str); RedrawInputLine(); return; case ConsoleKey.Backspace: if (inputString.Length < 1) { return; } inputString = inputString.Substring(0, inputString.Length - 1); RedrawInputLine(); return; case ConsoleKey.Escape: inputString = string.Empty; RedrawInputLine(); return; case ConsoleKey.UpArrow: if (inputHistory.Count == 0) { return; } if (inputHistoryIndex < 0) { inputHistoryIndex = 0; } if (inputHistoryIndex >= inputHistory.Count - 1) { inputHistoryIndex = inputHistory.Count - 1; inputString = inputHistory[inputHistoryIndex]; RedrawInputLine(); return; } inputString = inputHistory[inputHistoryIndex++]; RedrawInputLine(); return; case ConsoleKey.DownArrow: if (inputHistory.Count == 0) { return; } if (inputHistoryIndex >= inputHistory.Count - 1) { inputHistoryIndex = inputHistory.Count - 2; } inputString = inputHistoryIndex < 0 ? string.Empty : inputHistory[inputHistoryIndex--]; RedrawInputLine(); return; case ConsoleKey.Tab: var results = Completion?.Invoke(inputString); if (results == null || results.Length == 0) { return; } if (results.Length > 1) { ClearLine(Interface.Oxide.Config.Console.ShowStatusBar ? StatusTextLeft.Length + 1 : 1); Console.ForegroundColor = ConsoleColor.Yellow; var lowestDiff = results.Max(r => r.Length); for (var index = 0; index < results.Length; index++) { var result = results[index]; if (index > 0) { var diff = GetFirstDiffIndex(results[0], result); if (diff > 0 && diff < lowestDiff) { lowestDiff = diff; } } Console.WriteLine(result); } if (lowestDiff > 0) { inputString = results[0].Substring(0, lowestDiff); } RedrawInputLine(); return; } inputString = results[0]; RedrawInputLine(); return; } if (consoleKeyInfo.KeyChar == 0) { return; } inputString = string.Concat(inputString, consoleKeyInfo.KeyChar); RedrawInputLine(); }