Package org.jline.reader.impl
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 TypeMethodDescriptionint
atChar
(int i) Returns the character at the specified position in the buffer.boolean
Issue a backspace.int
backspace
(int num) Issue num backspaces.boolean
clear()
Clears the buffer content.copy()
Creates a copy of this buffer.void
Copies the content and cursor position from another buffer.int
currChar()
Returns the character at the current cursor position.boolean
currChar
(int ch) Replaces the character at the current cursor position.int
cursor()
Returns the current cursor position in the buffer.boolean
cursor
(int position) Move the cursor position to the specified absolute index.boolean
delete()
Deletes the character at the cursor position.int
delete
(int num) Deletes multiple characters starting at the cursor position.boolean
down()
Moves the cursor down one line while maintaining the same column position if possible.int
length()
Returns the length of the buffer.int
move
(int num) Move the cursor where characters.boolean
moveXY
(int dx, int dy) Moves the cursor by the specified number of columns and rows.int
nextChar()
Returns the character after the current cursor position.int
prevChar()
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()
boolean
up()
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.void
write
(int c) Write the specific character into the buffer, setting the cursor position ahead one.void
write
(int c, boolean overTyping) Write the specific character into the buffer, setting the cursor position ahead one.void
write
(CharSequence str) Insert the specified chars into the buffer, setting the cursor to the end of the insertion point.void
write
(CharSequence str, boolean overTyping) Writes a string at the current cursor position and advances the cursor.void
zeroOut()
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:Buffer
Creates a copy of this buffer. -
cursor
public int cursor()Description copied from interface:Buffer
Returns the current cursor position in the buffer. -
length
public int length()Description copied from interface:Buffer
Returns the length of the buffer. -
currChar
public boolean currChar(int ch) Description copied from interface:Buffer
Replaces the character at the current cursor position. -
currChar
public int currChar()Description copied from interface:Buffer
Returns the character at the current cursor position. -
prevChar
public int prevChar()Description copied from interface:Buffer
Returns the character before the current cursor position. -
nextChar
public int nextChar()Description copied from interface:Buffer
Returns the character after the current cursor position. -
atChar
public int atChar(int i) Description copied from interface:Buffer
Returns the character at the specified position in the buffer. -
write
public void write(int c) Write the specific character into the buffer, setting the cursor position ahead one. -
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:Buffer
Writes a string at the current cursor position and advances the cursor. -
clear
public boolean clear()Description copied from interface:Buffer
Clears the buffer content. -
substring
Description copied from interface:Buffer
Returns a substring of the buffer from the specified start position to the end. -
substring
Description copied from interface:Buffer
Returns a substring of the buffer from the specified start position to the specified end position. -
upToCursor
Description copied from interface:Buffer
Returns a substring of the buffer from the beginning to the current cursor position.- Specified by:
upToCursor
in interfaceBuffer
- Returns:
- the substring
-
cursor
public boolean cursor(int position) Move the cursor position to the specified absolute index. -
move
public int move(int num) Move the cursor where characters. -
up
public boolean up()Description copied from interface:Buffer
Moves 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:Buffer
Moves 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:Buffer
Moves the cursor by the specified number of columns and rows. This is used for multi-line editing. -
backspace
public int backspace(int num) Issue num backspaces. -
backspace
public boolean backspace()Issue a backspace. -
delete
public int delete(int num) Description copied from interface:Buffer
Deletes multiple characters starting at the cursor position. -
delete
public boolean delete()Description copied from interface:Buffer
Deletes the character at the cursor position. -
toString
-
copyFrom
Description copied from interface:Buffer
Copies the content and cursor position from another buffer. -
zeroOut
public void zeroOut()Description copied from interface:Buffer
Clear any internal buffer.
-