public static void YankNthArg(ConsoleKeyInfo?key = null, object arg = null) { var yankLastArgState = new YankLastArgState { argument = (arg is int) ? (int)arg : 1, historyIndex = _singleton._currentHistoryIndex - 1, }; _singleton.YankArgImpl(yankLastArgState); }
void YankArgImpl(YankLastArgState yankLastArgState) { if (yankLastArgState.historyIndex < 0 || yankLastArgState.historyIndex >= _history.Count) { Ding(); return; } Token[] tokens; ParseError[] errors; var buffer = _history[yankLastArgState.historyIndex]; Parser.ParseInput(buffer._line, out tokens, out errors); int arg = (yankLastArgState.argument < 0) ? tokens.Length + yankLastArgState.argument - 1 : yankLastArgState.argument; if (arg < 0 || arg >= tokens.Length) { Ding(); return; } var argText = tokens[arg].Text; if (yankLastArgState.startPoint < 0) { yankLastArgState.startPoint = _current; Insert(argText); } else { Replace(yankLastArgState.startPoint, _current - yankLastArgState.startPoint, argText); } }
/// <summary> /// Yank the first argument (after the command) from the previous history line. /// With an argument, yank the nth argument (starting from 0), if the argument /// is negative, start from the last argument. /// </summary> public static void YankNthArg(ConsoleKeyInfo? key = null, object arg = null) { var yankLastArgState = new YankLastArgState { argument = (arg is int) ? (int)arg : 1, historyIndex = _singleton._currentHistoryIndex - 1, }; _singleton.YankArgImpl(yankLastArgState); }