Class BufferImpl
java.lang.Object
org.jline.reader.impl.BufferImpl
- All Implemented Interfaces:
Buffer
Default implementation of the
Buffer interface.
This class provides a mutable buffer for storing and manipulating the text being edited in the LineReader. It maintains the text content and the current cursor position, and provides methods for text insertion, deletion, and cursor movement.
Key features include:
- Efficient text insertion and deletion with a gap buffer implementation
- Support for Unicode characters beyond the Basic Multilingual Plane
- Cursor movement in both character and line coordinates
- Copy and paste operations
- Secure clearing of buffer contents
The buffer uses a gap buffer data structure for efficient editing operations, which provides good performance for the typical editing patterns in a line editor.
- Since:
- 2.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new buffer with the default size (64).BufferImpl(int size) Creates a new buffer with the specified size. -
Method Summary
Modifier and TypeMethodDescriptionintatChar(int i) Returns the character at the specified position in the buffer.booleanIssue a backspace.intbackspace(int num) Issue num backspaces.booleanclear()Clears the buffer content.copy()Creates a copy of this buffer.voidCopies the content and cursor position from another buffer.intcurrChar()Returns the character at the current cursor position.booleancurrChar(int ch) Replaces the character at the current cursor position.intcursor()Returns the current cursor position in the buffer.booleancursor(int position) Move the cursor position to the specified absolute index.booleandelete()Deletes the character at the cursor position.intdelete(int num) Deletes multiple characters starting at the cursor position.booleandown()Moves the cursor down one line while maintaining the same column position if possible.intlength()Returns the length of the buffer.intmove(int num) Move the cursor where characters.booleanmoveXY(int dx, int dy) Moves the cursor by the specified number of columns and rows.intnextChar()Returns the character after the current cursor position.intprevChar()Returns the character before the current cursor position.substring(int start) Returns a substring of the buffer from the specified start position to the end.substring(int start, int end) Returns a substring of the buffer from the specified start position to the specified end position.toString()booleanup()Moves the cursor up one line while maintaining the same column position if possible.Returns a substring of the buffer from the beginning to the current cursor position.voidwrite(int c) Write the specific character into the buffer, setting the cursor position ahead one.voidwrite(int c, boolean overTyping) Write the specific character into the buffer, setting the cursor position ahead one.voidwrite(CharSequence str) Insert the specified chars into the buffer, setting the cursor to the end of the insertion point.voidwrite(CharSequence str, boolean overTyping) Writes a string at the current cursor position and advances the cursor.voidzeroOut()Clear any internal buffer.
-
Constructor Details
-
BufferImpl
public BufferImpl()Creates a new buffer with the default size (64). -
BufferImpl
public BufferImpl(int size) Creates a new buffer with the specified size.- Parameters:
size- the initial size of the buffer
-
-
Method Details
-
copy
Description copied from interface:BufferCreates a copy of this buffer. -
cursor
-
length
-
currChar
-
currChar
-
prevChar
-
nextChar
-
atChar
-
write
-
write
public void write(int c, boolean overTyping) Write the specific character into the buffer, setting the cursor position ahead one. The text may overwrite or insert based on the current setting ofoverTyping. -
write
Insert the specified chars into the buffer, setting the cursor to the end of the insertion point. -
write
Description copied from interface:BufferWrites a string at the current cursor position and advances the cursor. -
clear
-
substring
-
substring
Description copied from interface:BufferReturns a substring of the buffer from the specified start position to the specified end position. -
upToCursor
Description copied from interface:BufferReturns a substring of the buffer from the beginning to the current cursor position.- Specified by:
upToCursorin interfaceBuffer- Returns:
- the substring
-
cursor
-
move
-
up
public boolean up()Description copied from interface:BufferMoves the cursor up one line while maintaining the same column position if possible. This is used for multi-line editing. -
down
public boolean down()Description copied from interface:BufferMoves the cursor down one line while maintaining the same column position if possible. This is used for multi-line editing. -
moveXY
public boolean moveXY(int dx, int dy) Description copied from interface:BufferMoves the cursor by the specified number of columns and rows. This is used for multi-line editing. -
backspace
-
backspace
-
delete
-
delete
-
toString
-
copyFrom
-
zeroOut
-