Ejemplo n.º 1
0
        /// <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);
            }
        }
        /// <summary>
        /// Get next available value from command history
        /// </summary>
        /// <returns></returns>
        internal static string GetNext()
        {
            if (!historySerial.NextAvailable())
            {
                historySerial.CursorToEnd();
                return(null);
            }

            string next = historySerial.Next();

            AddToBuffer(next);
            historySerial.Update(Encoding.UTF8.GetString(_userCommandInput.ToArray(), 0, _userCommandInput.Count));

            return(next);
        }