/// <summary> /// Get previous value from command history /// </summary> /// <returns></returns> internal static string GetPrevious() { string previous = historySerial.Previous(); AddToBuffer(previous); historySerial.Update(Encoding.UTF8.GetString(_userCommandInput.ToArray(), 0, _userCommandInput.Count)); return(previous); }
/// <summary> /// Handle UP arrow key to get the previous command executed /// </summary> void HandleUpArrow() { if (!cmdhistory.PreviousAvailable()) { return; } cmdhistory.Update(buffer.ToString()); string value = cmdhistory.Previous(); if (value != null) { // If max window size is reached, start writing on the next line if (buffer.Length > (Console.WindowWidth - prompt.Length)) { // Calculate the number of lines based on the buffer length and window size int line = ((buffer.Length + prompt.Length) / Console.BufferWidth); if (cursorPtr > (Console.BufferWidth - prompt.Length)) { ClearConsoleLine(); if (Console.CursorTop - line >= 0) { Console.SetCursorPosition(prompt.Length, Console.CursorTop - line); } ClearConsoleLine(); } else { if (Console.CursorTop + 1 <= Console.BufferHeight) { Console.SetCursorPosition(Console.CursorLeft, Console.CursorTop + 1); } ClearConsoleLine(); if (Console.CursorTop - 1 >= 0) { Console.SetCursorPosition(0, Console.CursorTop - 1); } if (Console.CursorTop - line >= 0) { Console.SetCursorPosition(prompt.Length, Console.CursorTop - line); } } } else { ClearConsoleLine(); } SetText(value); } }