Beispiel #1
0
        protected void HandleInsert(char character)
        {
            // Remember the column position of the cursor
            CursorPosition position = new CursorPosition(Console.CursorLeft, Console.CursorTop);

            // Get editor buffer-aware line and column indicies
            int zeroIndexedCurrentLine   = editor.EditorBuffer.CurrentLineIndex;
            int zeroIndexedCurrentColumn = editor.EditorBuffer.CurrentColumnIndex;

            // Insert character
            editor.GetTextBuffer().Insert(zeroIndexedCurrentLine, zeroIndexedCurrentColumn, character);

            // Restore the column position of the curor before rewriting the line
            position.Restore();

            // Advance cursor position by one
            editor.EditorBuffer.AdvanceCursor();
        }
Beispiel #2
0
        public void paint()
        {
            // Remember console configuration
            CursorPosition originalCursorPosition = new CursorPosition(
                Console.CursorLeft,
                Console.CursorTop
                );
            ColorConfiguration originalColorConfiguration = new ColorConfiguration(
                Console.BackgroundColor,
                Console.ForegroundColor
                );


            position.Restore();
            colorConfiguration.Restore();

            Console.Write(GenerateContent());

            // Reset stored configuration
            originalColorConfiguration.Restore();
            originalCursorPosition.Restore();
        }
Beispiel #3
0
        protected void HandleBackpace()
        {
            // Remember the column position of the cursor
            CursorPosition position = new CursorPosition(Console.CursorLeft, Console.CursorTop);

            // Get editor buffer-aware line and column indicies
            int zeroIndexedCurrentLine      = editor.EditorBuffer.CurrentLineIndex;
            int zeroIndexedCurrentColumn    = editor.EditorBuffer.CurrentColumnIndex;
            int zeroIndexedPositionToDelete = zeroIndexedCurrentColumn - 1;

            if (zeroIndexedPositionToDelete < 0)
            {
                if (zeroIndexedCurrentLine > 0)
                {
                    int    textLengthFromPreviouLine = editor.TextBuffer.GetLine(zeroIndexedCurrentLine - 1).Length;
                    string textFromCurrentLine       = editor.TextBuffer.GetLine(zeroIndexedCurrentLine);
                    editor.TextBuffer.RemoveLine(zeroIndexedCurrentLine);
                    editor.TextBuffer.AppendToLine(zeroIndexedCurrentLine - 1, textFromCurrentLine);

                    // Need to tell editor.EditorBuffer where cursor should be
                    editor.EditorBuffer.MoveCursorTo(textLengthFromPreviouLine, zeroIndexedCurrentLine);
                }
                else
                {
                    return;
                }
            }
            else
            {
                // Remove the character from the underlying text buffer
                editor.GetTextBuffer().Remove(zeroIndexedCurrentLine, zeroIndexedPositionToDelete, 1);

                // Reset cursor position
                position.Restore();

                // Advance curson position back by one
                editor.EditorBuffer.MoveCursorLeft();
            }
        }
Beispiel #4
0
 // Fluent Interface
 public StatusBuffer AtPosition(CursorPosition position)
 {
     this.position = position;
     return(this);
 }
Beispiel #5
0
 public EditorBuffer AtPosition(CursorPosition position)
 {
     rootPosition = position;
     return(this);
 }
 public EditorBufferLine AtPosition(CursorPosition position)
 {
     this.rootPosition = position;
     return(this);
 }