org.crsh.term.console
Class Console

java.lang.Object
  extended by org.crsh.term.console.Console

public final class Console
extends Object

This class provides an abstraction for a console. This implementation wraps the input and output of a terminal based on a bidirectional io.

Interactions between terminal and console are done though the ViewReader and ViewWriter classes.

Version:
$Revision$
Author:
Julien Viet

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  LinkedList<CharSequence> lines
          .
private  boolean previousCR
          Do we have a issued a CR previously?
private  ConsoleReader reader
          .
private  int size
          .
private  ViewReader viewReader
          .
private  ViewWriter viewWriter
          .
private  ConsoleWriter writer
          .
 
Constructor Summary
Console(ViewWriter viewWriter)
           
 
Method Summary
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.
 void clearBuffer()
          Clears the buffer without doing any echoing.
private  boolean echo(char c)
           
private  void echo(String s)
           
private  boolean echoCRLF()
           
private  boolean echoDel()
           
 CharSequence getBuffer()
           
 CharSequence getBufferToCursor()
           
 ConsoleReader getReader()
          Returns the console reader.
 ViewReader getViewReader()
           
 ConsoleWriter getWriter()
           
 boolean isEchoing()
           
private  boolean moveLeft()
           
private  boolean moveRight()
           
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 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.


viewWriter

private final ViewWriter viewWriter
.


viewReader

private final ViewReader viewReader
.


reader

private final ConsoleReader reader
.


writer

private final ConsoleWriter writer
.

Constructor Detail

Console

public Console(ViewWriter viewWriter)
Method Detail

clearBuffer

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


getBuffer

public CharSequence getBuffer()

getBufferToCursor

public CharSequence getBufferToCursor()

isEchoing

public boolean isEchoing()

setEchoing

public void setEchoing(boolean echoing)

getReader

public ConsoleReader getReader()
Returns the console reader.

Returns:
the console reader

getViewReader

public ViewReader getViewReader()

getWriter

public ConsoleWriter getWriter()

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

moveRight

private boolean moveRight()
                   throws IOException
Throws:
IOException

moveLeft

private boolean moveLeft()
                  throws IOException
Throws:
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 © 2012 eXo Platform SAS. All Rights Reserved.