org.crsh.telnet.term.console
Class TermIOBuffer

java.lang.Object
  extended by org.crsh.telnet.term.console.TermIOBuffer
All Implemented Interfaces:
Appendable, Iterator<CharSequence>

public final class TermIOBuffer
extends Object
implements Appendable, Iterator<CharSequence>


Field Summary
private  char[] buffer
          .
private  int curAt
          Cursor Position, always equal to size unless the underlying *.IO class supports editing.
private  boolean echoing
          Whether or not we do echoing.
private  TermIO io
          .
private  LinkedList<CharSequence> lines
          .
private  boolean previousCR
          Do we have a issued a CR previously?
private  int size
          .
 
Constructor Summary
TermIOBuffer(TermIO io)
           
 
Method Summary
 TermIOBuffer append(char c)
           
 TermIOBuffer append(CharSequence s)
           
 TermIOBuffer append(CharSequence csq, int start, int end)
           
private  boolean appendData(char c)
          Append a char at the current cursor position and increment the cursor position.
private  boolean 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.
 void clear()
          Clears the buffer without doing any echoing.
 int del()
          Delete the char under the cursor or return -1 if no char was deleted.
private  boolean echo(char c)
           
private  void echo(String s)
           
private  boolean echoCRLF()
           
private  boolean echoDel()
           
(package private)  CharSequence getBufferToCursor()
           
(package private)  int getCursor()
          Returns the current cursor position.
 int getSize()
          Returns the total number of chars in the buffer, independently of the cursor position.
 boolean hasNext()
           
(package private)  boolean isEchoing()
           
 boolean moveLeft()
           
(package private)  int moveLeft(int count)
           
 boolean moveRight()
           
 int moveRight(int count)
           
 CharSequence next()
           
private  int pop()
          Popup one char from buffer at the current cursor position.
private  boolean push(char c)
          Push one char in the buffer at the current cursor position.
 void remove()
           
(package private)  CharSequence replace(CharSequence s)
          Replace all the characters before the cursor by the provided char sequence.
(package private)  void setEchoing(boolean echoing)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

private char[] buffer
.


size

private int size
.


curAt

private int curAt
Cursor Position, always equal to size unless the underlying *.IO class supports editing.


lines

private LinkedList<CharSequence> lines
.


previousCR

private boolean previousCR
Do we have a issued a CR previously?


echoing

private boolean echoing
Whether or not we do echoing.


io

private final TermIO io
.

Constructor Detail

TermIOBuffer

public TermIOBuffer(TermIO io)
Method Detail

clear

public void clear()
Clears the buffer without doing any echoing.


getSize

public 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 IndexOutOfBoundsException
Returns a character at a specified index in the buffer.

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

getBufferToCursor

CharSequence getBufferToCursor()

isEchoing

boolean isEchoing()

setEchoing

void setEchoing(boolean echoing)

hasNext

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

next

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

remove

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

append

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

append

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

append

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

replace

CharSequence 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

public boolean moveRight()
                  throws IOException
Throws:
IOException

moveLeft

public boolean moveLeft()
                 throws IOException
Throws:
IOException

moveRight

public int moveRight(int count)
              throws IOException,
                     IllegalArgumentException
Throws:
IOException
IllegalArgumentException

moveLeft

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

del

public 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 boolean appendData(CharSequence s,
                           int start,
                           int end)
                    throws IOException
Throws:
IOException

appendData

private boolean appendData(char c)
                    throws IOException
Append a char at the current cursor position and increment the cursor position.

Parameters:
c - the char to append
Returns:
true if flush is required
Throws:
IOException - any 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

echo

private boolean echo(char c)
              throws IOException
Throws:
IOException

echo

private void echo(String s)
           throws IOException
Throws:
IOException

echoDel

private boolean echoDel()
                 throws IOException
Throws:
IOException

echoCRLF

private boolean 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

push

private boolean push(char c)
Push one char in the buffer at the current cursor position. This operation ensures that the buffer is large enough and it may increase the buffer capacity when required. The cursor position is incremented when a char is appended at the last position, otherwise the cursor position remains unchanged.

Parameters:
c - the char to push
Returns:
true if the cursor position was incremented


Copyright © 2015 eXo Platform SAS. All Rights Reserved.