PowerArgs.Cli.RichCommandLineContext.ReplaceConsole C# (CSharp) Method

ReplaceConsole() public method

Rewrites the console using the latest values in the Buffer and moves the cursor to the end of the line.
public ReplaceConsole ( ConsoleString newBuffer ) : void
newBuffer ConsoleString The new line of text that will replace the current buffer.
return void
        public void ReplaceConsole(ConsoleString newBuffer)
        {
            this.Console.CursorLeft = this.ConsoleStartLeft;
            this.Console.CursorTop = this.ConsoleStartTop;
            for (int i = 0; i < newBuffer.Length; i++)
            {
                this.Console.Write(newBuffer[i]);
            }

            var newLeft = this.Console.CursorLeft;
            var newTop = this.Console.CursorTop;

            for (int i = 0; i < this.Buffer.Count - newBuffer.Length; i++)
            {
                this.Console.Write(" ");
            }

            this.Console.CursorTop = newTop;
            this.Console.CursorLeft = newLeft;
            this.Buffer = newBuffer.ToList(); ;
        }

Usage Example

        private void HandleDownArrow(RichCommandLineContext context)
        {
            if (context.HistoryManager.Values.Count == 0)
            {
                return;
            }

            context.Console.CursorLeft = context.ConsoleStartLeft;
            context.HistoryManager.Index--;
            if (context.HistoryManager.Index < 0)
            {
                context.HistoryManager.Index = context.HistoryManager.Values.Count - 1;
            }

            var newChars = context.HistoryManager.Values[context.HistoryManager.Index];
            context.ReplaceConsole(newChars);
            context.Intercept = true;
        }
All Usage Examples Of PowerArgs.Cli.RichCommandLineContext::ReplaceConsole