protected override void ProcessKey(ConsoleKeyInfo consoleKey, InputState inputState) { switch(consoleKey.Key) { case ConsoleKey.End: if(inputState.CarrageIndex < inputState.Line.Length) { inputState.GotoEnd(); } break; case ConsoleKey.Home: if(inputState.CarrageIndex > 0) { inputState.GotoBegin(); } break; case ConsoleKey.LeftArrow: if(inputState.CarrageIndex > 0) { inputState.CarrageIndex--; Console.Write('\b'); } break; case ConsoleKey.RightArrow: if(inputState.CarrageIndex < inputState.Line.Length) { Console.Write(inputState.Line.ToString().Substring(inputState.CarrageIndex, 1)); inputState.CarrageIndex++; } break; default: base.ProcessKey(consoleKey, inputState); return; } }
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); }