org.crsh.console
Class EditorBuffer

java.lang.Object
  extended by org.crsh.console.EditorBuffer
All Implemented Interfaces:
Appendable, Iterator<String>

final class EditorBuffer
extends Object
implements Appendable, Iterator<String>


Field Summary
private  StringBuilder current
          .
private  int cursor
          Cursor position.
private  ConsoleDriver driver
          The output.
private  LinkedList<String> lines
          Previous lines.
private  boolean needFlush
          True if flush is needed.
 
Constructor Summary
EditorBuffer(ConsoleDriver driver)
           
 
Method Summary
 EditorBuffer append(char c)
           
 EditorBuffer append(CharSequence s)
           
 EditorBuffer append(CharSequence csq, int start, int end)
           
private  void appendData(CharSequence s, int start, int end)
           
private  int appendDel()
          Delete the char before the cursor.
(package private)  char charAt(int index)
          Returns a character at a specified index in the buffer.
(package private)  int del()
          Delete the char under the cursor or return -1 if no char was deleted.
private  void echoCRLF()
           
private  void echoDel()
           
(package private)  void flush()
           
(package private)  void flush(boolean force)
           
(package private)  int getCursor()
          Returns the current cursor position.
 String getLine()
           
 List<String> getLines()
           
(package private)  int getSize()
          Returns the total number of chars in the buffer, independently of the cursor position.
 boolean hasNext()
           
(package private)  boolean moveLeft()
           
(package private)  int moveLeftBy(int count)
           
(package private)  boolean moveRight()
           
(package private)  boolean moveRight(char c)
          Move the cursor right by one char with the provided char.
(package private)  int moveRightBy(int count)
           
private  void newAppendNoLF(CharSequence s, int start, int end)
           
 String next()
           
private  int pop()
          Popup one char from buffer at the current cursor position.
 void remove()
           
(package private)  String replace(CharSequence s)
          Replace all the characters before the cursor by the provided char sequence.
(package private)  void reset()
          Reset the buffer state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

current

private StringBuilder current
.


cursor

private int cursor
Cursor position.


lines

private LinkedList<String> lines
Previous lines.


driver

private final ConsoleDriver driver
The output.


needFlush

private boolean needFlush
True if flush is needed.

Constructor Detail

EditorBuffer

EditorBuffer(ConsoleDriver driver)
Method Detail

flush

void flush()
     throws IOException
Throws:
IOException

flush

void flush(boolean force)
     throws IOException
Throws:
IOException

reset

void reset()
Reset the buffer state.


getSize

int getSize()
Returns the total number of chars in the buffer, independently of the cursor position.

Returns:
the number of chars

getCursor

int getCursor()
Returns the current cursor position.

Returns:
the cursor position

charAt

char charAt(int index)
      throws StringIndexOutOfBoundsException
Returns a character at a specified index in the buffer.

Parameters:
index - the index
Returns:
the char
Throws:
StringIndexOutOfBoundsException - if the index is negative or larget than the size

getLine

public String getLine()
Returns:
the current line

getLines

public List<String> getLines()
Returns:
the lines

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<String>

next

public String next()
Specified by:
next in interface Iterator<String>

remove

public void remove()
Specified by:
remove in interface Iterator<String>

append

public EditorBuffer append(char c)
                    throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public EditorBuffer append(CharSequence s)
                    throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

append

public EditorBuffer append(CharSequence csq,
                           int start,
                           int end)
                    throws IOException
Specified by:
append in interface Appendable
Throws:
IOException

replace

String replace(CharSequence s)
         throws IOException
Replace all the characters before the cursor by the provided char sequence.

Parameters:
s - the new char sequence
Returns:
the l
Throws:
IOException - any IOException

moveRight

boolean moveRight(char c)
            throws IOException
Move the cursor right by one char with the provided char.

Parameters:
c - the char to overwrite
Returns:
true if it happended
Throws:
IOException

moveRight

boolean moveRight()
            throws IOException
Throws:
IOException

moveLeft

boolean moveLeft()
           throws IOException
Throws:
IOException

moveRightBy

int moveRightBy(int count)
          throws IOException,
                 IllegalArgumentException
Throws:
IOException
IllegalArgumentException

moveLeftBy

int moveLeftBy(int count)
         throws IOException,
                IllegalArgumentException
Throws:
IOException
IllegalArgumentException

del

int del()
  throws IOException
Delete the char under the cursor or return -1 if no char was deleted.

Returns:
the deleted char
Throws:
IOException - any IOException

appendData

private void appendData(CharSequence s,
                        int start,
                        int end)
                 throws IOException
Throws:
IOException

newAppendNoLF

private void newAppendNoLF(CharSequence s,
                           int start,
                           int end)
                    throws IOException
Throws:
IOException

appendDel

private int appendDel()
               throws IOException
Delete the char before the cursor.

Returns:
the removed char value or -1 if no char was removed
Throws:
IOException - any IOException

echoDel

private void echoDel()
              throws IOException
Throws:
IOException

echoCRLF

private void echoCRLF()
               throws IOException
Throws:
IOException

pop

private int pop()
Popup one char from buffer at the current cursor position.

Returns:
the popped char or -1 if none was removed


Copyright © 2015 eXo Platform SAS. All Rights Reserved.