public void Entered() { switch (CurrentInput.ToLower()) { case "exit": FancyConsole.Log(new FancyText("[Exit] ", FancyColor.Red) { Next = new FancyText("Shutting down...", FancyColor.Reset) }); Environment.Exit(0); break; case "debug": FancyConsole.Debug = !FancyConsole.Debug; FancyConsole.Log(new FancyText("[Debug] ", FancyColor.Aqua) { Next = FancyConsole.Debug ? new FancyText("Enabled", FancyColor.Green) : new FancyText("Disabled", FancyColor.Red) }); break; default: FancyConsole.Log(new FancyText("[Entered] ", FancyColor.Green) { Next = new FancyText(CurrentInput, FancyColor.Reset) }); break; } History.Insert(0, CurrentInput); CurrentInput = ""; LeftInput = ""; RightInput = ""; CurrentArg = ""; InputStrip = ""; SavedInput = ""; Cursor = 0; HistoryIndex = -1; Hints = new string[0]; VisibleHints = new string[0]; HintsIndex = 0; }
public void ParseInput() { if (FancyConsole.Debug) { FancyConsole.Log(new FancyText("[Key] ", FancyColor.Green) { Next = new FancyText( Key.Key + ":" + Key.Modifiers + ":" + Key.Modifiers.HasFlag(ConsoleModifiers.Shift) + ":" + ((int)Key.KeyChar), FancyColor.Reset) }); } switch (Key.Key) { case ConsoleKey.Tab: if (Hints == null || Hints.Length == 0) { GetHints(); } else if (Key.Modifiers.HasFlag(ConsoleModifiers.Shift)) { DecrHint(); } else { IncrHint(); } break; case ConsoleKey.Backspace: if (Cursor > 0) { var reset = LeftInput.Length > 1 && LeftInput[^ 1] == ' ' || LeftInput.Length == 1; LeftInput = LeftInput.Substring(0, LeftInput.Length - 1); MoveCursor(-1); UpdateInputs(); UpdateVisibleHints(); if (reset) { SpaceReset(); } } break; case ConsoleKey.Delete: if (Cursor < CurrentInput.Length) { RightInput = RightInput.Substring(1, RightInput.Length - 1); MoveCursor(0); UpdateInputs(); UpdateVisibleHints(); } break; case ConsoleKey.LeftArrow: MoveCursor(-1); UpdateLeftRight(); UpdateInputs(); if (LeftInput.Length > 0 && LeftInput[^ 1] == ' ') { SpaceReset(); } else { UpdateVisibleHints(); } break; case ConsoleKey.RightArrow: MoveCursor(1); UpdateLeftRight(); UpdateInputs(); if (LeftInput.Length > 0 && LeftInput[^ 1] == ' ') { SpaceReset(); } else { UpdateVisibleHints(); } break; case ConsoleKey.Enter: if (string.IsNullOrEmpty(CurrentHint) || Key.Modifiers.HasFlag(ConsoleModifiers.Shift)) { Entered(); } else { SelectHint(); } break; case ConsoleKey.PageUp: //For some reason, shift + arrow = Page Lm.OffsetScroll(Key.Modifiers.HasFlag(ConsoleModifiers.Shift) ? -1 : -PrintManager.MaxLines() + 2); Pm.DrawLogs(); break; case ConsoleKey.PageDown: Lm.OffsetScroll(Key.Modifiers.HasFlag(ConsoleModifiers.Shift) ? 1 : PrintManager.MaxLines() - 2); Pm.DrawLogs(); break; case ConsoleKey.UpArrow: OffsetHistory(1); break; case ConsoleKey.DownArrow: OffsetHistory(-1); break; case ConsoleKey.Home: Lm.Scroll = 0; Pm.DrawLogs(); break; case ConsoleKey.End: Lm.Scroll = Math.Max(Lm.Lines.Count - PrintManager.MaxLines() + 1, 0); Pm.DrawLogs(); break; case ConsoleKey.Escape: Hints = new string[0]; VisibleHints = new string[0]; CurrentHint = ""; HintsIndex = -1; break; case ConsoleKey.R: if (Key.Modifiers.HasFlag(ConsoleModifiers.Control)) { FancyConsole.RefreshScreen(); return; } else { AddInput(Key.KeyChar); } break; default: AddInput(Key.KeyChar); break; } Pm.DrawInput(); Pm.DrawHints(); }