protected override void ProcessKey(ConsoleKeyInfo consoleKey, InputState inputState) { switch(consoleKey.Key) { case ConsoleKey.Backspace: if(inputState.CarrageIndex > 0) { inputState.Line.Remove(inputState.CarrageIndex - 1, 1); inputState.CarrageIndex--; Console.Write("\b"); inputState.RefreshTail(1); } break; case ConsoleKey.Delete: if(inputState.CarrageIndex < inputState.Line.Length) { inputState.Line.Remove(inputState.CarrageIndex, 1); inputState.RefreshTail(1); } break; default: base.ProcessKey(consoleKey, inputState); break; } }
protected override void ProcessKey(ConsoleKeyInfo consoleKey, InputState inputState) { if(consoleKey.Key == ConsoleKey.Enter) inputState.Done = true; else if(consoleKey.KeyChar != '\0') { inputState.Line.Insert(inputState.CarrageIndex, consoleKey.KeyChar); Console.Write(consoleKey.KeyChar); inputState.CarrageIndex++; inputState.RefreshTail(); } }
private void PutLineFromHistory(InputState inputState, int historyIndex) { int oldLength = inputState.Line.Length; string newLine = history[historyIndex]; inputState.GotoBegin(); inputState.Line.Clear(); inputState.Line.Append(newLine); inputState.GotoEnd(); if(newLine.Length < oldLength) inputState.RefreshTail(oldLength - newLine.Length); }