| Method from com.sshtools.daemon.terminal.Editline Detail: |
public void append(char ch) throws IOException, BufferOverflowException {
storeSize();
//buffer
buf.ensureSpace(1);
buf.append(ch);
//cursor
Cursor++;
//screen
if (!maskInput) {
myIO.write(ch);
} else {
myIO.write(mask);
}
}
|
public void append(String str) throws IOException, BufferOverflowException {
storeSize();
//buffer
buf.ensureSpace(str.length());
for (int i = 0; i < str.length(); i++) {
buf.append(str.charAt(i));
//Cursor
Cursor++;
}
//screen
if (!maskInput) {
myIO.write(str);
} else {
for (int i = 0; i < str.length(); i++) {
myIO.write(mask);
}
}
}
|
public void clear() throws IOException {
storeSize();
//Buffer
buf.clear();
//Cursor
Cursor = 0;
//Screen
draw();
}
|
public void draw() throws IOException {
myIO.moveLeft(lastcurspos);
myIO.eraseToEndOfLine();
if (!maskInput) {
myIO.write(buf.toString());
} else {
for (int i = 0; i < buf.size(); i++) {
myIO.write(mask);
}
}
//adjust screen cursor hmm
if (Cursor < buf.size()) {
myIO.moveLeft(buf.size() - Cursor);
}
}
|
public int getCursorPosition() {
return Cursor;
}
|
public String getHardwrap() throws IOException, IndexOutOfBoundsException {
//Buffer
String content = buf.toString();
content = content.substring(Cursor, content.length());
//System.out.println("buffer:tostring:"+buf.toString()+":");
//System.out.println("buffer:size:"+buf.size());
int lastsize = buf.size();
for (int i = Cursor; i < lastsize; i++) {
buf.removeCharAt(Cursor);
//System.out.println("buffer:removing char #"+i);
}
//System.out.println("buffer:tostring:"+buf.toString()+":");
//cursor stays
//screen
myIO.eraseToEndOfLine();
return content;
}
|
public String getSoftwrap() throws IOException, IndexOutOfBoundsException {
//Wrap from Buffer
String content = buf.toString();
int idx = content.lastIndexOf(" ");
if (idx == -1) {
content = "";
} else {
//System.out.println("Line:softwrap:lastspace:"+idx);
content = content.substring(idx + 1, content.length());
//System.out.println("Line:softwrap:wraplength:"+content.length());
//Cursor
//remeber relative cursor pos
Cursor = size();
Cursor = Cursor - content.length();
//buffer
for (int i = 0; i < content.length(); i++) {
buf.removeCharAt(Cursor);
}
//screen
myIO.moveLeft(content.length());
myIO.eraseToEndOfLine();
//System.out.println("Line:softwrap:buffercontent:"+buf.toString());
}
return content + getLastRead();
}
|
public String getValue() {
return buf.toString();
}
|
public boolean isHardwrapped() {
return hardwrapped;
}
|
public boolean isInInsertMode() {
return InsertMode;
}
|
public void maskInput(boolean maskInput) {
this.maskInput = maskInput;
}
|
public int run() {
try {
int in = 0;
do {
//get next key
in = myIO.read();
//store cursorpos
lastcurspos = Cursor;
switch (in) {
case TerminalIO.LEFT:
if (!moveLeft()) {
return in;
}
break;
case TerminalIO.RIGHT:
if (!moveRight()) {
return in;
}
break;
case TerminalIO.BACKSPACE:
try {
if (Cursor == 0) {
return in;
} else {
removeCharAt(Cursor - 1);
}
} catch (IndexOutOfBoundsException ioobex) {
myIO.bell();
}
break;
case TerminalIO.DELETE:
try {
removeCharAt(Cursor);
} catch (IndexOutOfBoundsException ioobex) {
myIO.bell();
}
break;
case TerminalIO.ENTER:
case TerminalIO.UP:
case TerminalIO.DOWN:
case TerminalIO.TABULATOR:
return in;
default:
try {
handleCharInput(in);
} catch (BufferOverflowException boex) {
setLastRead((char) in);
return in;
}
}
myIO.flush();
} while (true);
} catch (IOException ioe) {
return TerminalIO.IOERROR;
}
}
|
public void setCursorPosition(int pos) {
if (buf.size() < pos) {
Cursor = buf.size();
} else {
Cursor = pos;
}
//System.out.println("Editline:cursor:"+Cursor);
}
|
public void setHardwrapped(boolean b) {
hardwrapped = b;
}
|
public void setInsertMode(boolean b) {
InsertMode = b;
}
|
public void setMask(char mask) {
this.mask = mask;
}
|
public void setValue(String str) throws IOException, BufferOverflowException {
storeSize();
//buffer
buf.clear();
//cursor
Cursor = 0;
//screen
myIO.moveLeft(lastSize);
myIO.eraseToEndOfLine();
append(str);
}
|
public int size() {
return buf.size();
}
|