Package org.jline.reader.impl
Class BufferImpl
- java.lang.Object
-
- org.jline.reader.impl.BufferImpl
-
- All Implemented Interfaces:
Buffer
public class BufferImpl extends java.lang.Object implements Buffer
Default implementation of theBufferinterface.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:
Buffer,LineReader.getBuffer()
-
-
Constructor Summary
Constructors Constructor Description BufferImpl()Creates a new buffer with the default size (64).BufferImpl(int size)Creates a new buffer with the specified size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intatChar(int i)Returns the character at the specified position in the buffer.booleanbackspace()Issue a backspace.intbackspace(int num)Issue num backspaces.booleanclear()Clears the buffer content.BufferImplcopy()Creates a copy of this buffer.voidcopyFrom(Buffer buf)Copies 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.java.lang.Stringsubstring(int start)Returns a substring of the buffer from the specified start position to the end.java.lang.Stringsubstring(int start, int end)Returns a substring of the buffer from the specified start position to the specified end position.java.lang.StringtoString()booleanup()Moves the cursor up one line while maintaining the same column position if possible.java.lang.StringupToCursor()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(java.lang.CharSequence str)Insert the specified chars into the buffer, setting the cursor to the end of the insertion point.voidwrite(java.lang.CharSequence str, boolean overTyping)Writes a string at the current cursor position and advances the cursor.voidzeroOut()Clear any internal buffer.
-
-
-
Method Detail
-
copy
public BufferImpl copy()
Description copied from interface:BufferCreates a copy of this buffer.
-
cursor
public int cursor()
Description copied from interface:BufferReturns the current cursor position in the buffer.
-
length
public int length()
Description copied from interface:BufferReturns the length of the buffer.
-
currChar
public boolean currChar(int ch)
Description copied from interface:BufferReplaces the character at the current cursor position.
-
currChar
public int currChar()
Description copied from interface:BufferReturns the character at the current cursor position.
-
prevChar
public int prevChar()
Description copied from interface:BufferReturns the character before the current cursor position.
-
nextChar
public int nextChar()
Description copied from interface:BufferReturns the character after the current cursor position.
-
atChar
public int atChar(int i)
Description copied from interface:BufferReturns 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
public void write(java.lang.CharSequence str)
Insert the specified chars into the buffer, setting the cursor to the end of the insertion point.
-
write
public void write(java.lang.CharSequence str, boolean overTyping)Description copied from interface:BufferWrites a string at the current cursor position and advances the cursor.
-
clear
public boolean clear()
Description copied from interface:BufferClears the buffer content.
-
substring
public java.lang.String substring(int start)
Description copied from interface:BufferReturns a substring of the buffer from the specified start position to the end.
-
substring
public java.lang.String substring(int start, int end)Description copied from interface:BufferReturns a substring of the buffer from the specified start position to the specified end position.
-
upToCursor
public java.lang.String 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
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: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
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:BufferDeletes multiple characters starting at the cursor position.
-
delete
public boolean delete()
Description copied from interface:BufferDeletes the character at the cursor position.
-
toString
public java.lang.String toString()
-
copyFrom
public void copyFrom(Buffer buf)
Description copied from interface:BufferCopies the content and cursor position from another buffer.
-
-