Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,43 @@ public interface IVT100EmulatorBackend {
*/
void clearAll();

/**
* Switches between the screen a shell writes to, which keeps its scrollback, and
* the one a full screen program is given, which has none. Leaving the alternate
* screen puts back exactly what was on the normal one, so a program that takes
* over the display does not cost the user the history behind it.
*
* @param enable whether to show the alternate screen
*/
default void enableAlternateScreen(boolean enable) {
enableAlternateScreen(enable, true);
}

/**
* As {@link #enableAlternateScreen(boolean)}, for the modes that differ in the
* cursor: 1049 saves it on the way in and restores it on the way out, as DECSC
* and DECRC do, while 47 and 1047 leave it where the program put it.
*
* @param enable whether to show the alternate screen
* @param cursor whether the cursor and its rendition come back with the normal screen
*/
void enableAlternateScreen(boolean enable, boolean cursor);

/**
* @return how many lines the normal screen keeps, history included, also while the
* alternate screen, which keeps none, is showing
*/
int getBufferLineLimit();

/**
* Sets how many lines the normal screen keeps, history included. While the
* alternate screen is showing, the limit is kept for the normal screen and
* applies once it is back, since the alternate screen keeps no history.
*
* @param bufferLineLimit the maximum number of lines, ignored when not positive
*/
void setBufferLineLimit(int bufferLineLimit);

/**
* Sets the Dimensions of the addressable scroll space of the screen....
* Keeps the cursor position relative to the bottom of the screen!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ public void clearAll() {
fBackend.clearAll();
}

@Override
public void enableAlternateScreen(boolean enable, boolean cursor) {
fWriter.println("enableAlternateScreen(" + enable + ", " + cursor + ')'); //$NON-NLS-1$ //$NON-NLS-2$
fBackend.enableAlternateScreen(enable, cursor);
}

@Override
public int getBufferLineLimit() {
return fBackend.getBufferLineLimit();
}

@Override
public void setBufferLineLimit(int bufferLineLimit) {
fWriter.println("setBufferLineLimit(" + bufferLineLimit + ')'); //$NON-NLS-1$
fBackend.setBufferLineLimit(bufferLineLimit);
}

@Override
public void deleteCharacters(int n) {
fWriter.println("deleteCharacters(" + n + ")"); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,15 @@ public class VT100Emulator implements ControlListener {
*/
final private IVT100EmulatorBackend text;
/**
* This field hold the saved absolute line number of the cursor when
* processing the "ESC 7" and "ESC 8" command sequences.
* The cursor saved by "ESC 7" (and CSI ? 1048 h) for "ESC 8", one slot per screen
* as in xterm: [0] on the normal screen, [1] on the alternate one, so a full screen
* program saving its cursor does not overwrite the one the shell saved.
*/
private int savedCursorLine = 0;
private final int[] savedCursorLine = new int[2];
private final int[] savedCursorColumn = new int[2];

/**
* This field hold the saved column number of the cursor when processing the
* "ESC 7" and "ESC 8" command sequences.
*/
private int savedCursorColumn = 0;
/** whether a program asked for the alternate screen (47, 1047 or 1049) */
private boolean alternateScreen;

/**
* This field holds an array of StringBuffer objects, each of which is one
Expand Down Expand Up @@ -197,6 +196,31 @@ public void setInputStreamReader(Reader reader) {
fReader = reader;
}

/**
* @see IVT100EmulatorBackend#setBufferLineLimit(int)
*/
public void setBufferLineLimit(int bufferLineLimit) {
text.setBufferLineLimit(bufferLineLimit);
}

/**
* @see IVT100EmulatorBackend#getBufferLineLimit()
*/
public int getBufferLineLimit() {
return text.getBufferLineLimit();
}

private void saveCursor() {
int screen = alternateScreen ? 1 : 0;
savedCursorLine[screen] = relativeCursorLine();
savedCursorColumn[screen] = getCursorColumn();
}

private void restoreCursor() {
int screen = alternateScreen ? 1 : 0;
moveCursor(savedCursorLine[screen], savedCursorColumn[screen]);
}

public void setDimensions(int lines, int cols) {
text.setDimensions(lines, cols);
ITerminalConnector telnetConnection = getConnector();
Expand Down Expand Up @@ -383,16 +407,15 @@ private void processNewText() throws IOException {
// Save cursor position and character attributes

ansiState = ANSISTATE_INITIAL;
savedCursorLine = relativeCursorLine();
savedCursorColumn = getCursorColumn();
saveCursor();
break;

case '8':
// Restore cursor and attributes to previously saved
// position

ansiState = ANSISTATE_INITIAL;
moveCursor(savedCursorLine, savedCursorColumn);
restoreCursor();
break;

case 'c':
Expand Down Expand Up @@ -486,6 +509,11 @@ private void processNewText() throws IOException {
}

private void resetTerminal() {
// a full reset (ESC c) puts the normal screen back first, history and all, as a
// reset before a connection does; else the history stays capped away and a
// later CSI ? 1049 l would bring back the screen from before the reset
text.enableAlternateScreen(false);
alternateScreen = false;
text.eraseAll();
text.setCursor(0, 0);
text.setStyle(text.getDefaultStyle());
Expand Down Expand Up @@ -1272,9 +1300,18 @@ private void processDecPrivateCommand_h() {
break;
case 47:
case 1047:
Comment thread
akurtakov marked this conversation as resolved.
Resolved
case 1048:
// Use Alternate Screen Buffer, the cursor staying where it is.
text.enableAlternateScreen(true, false);
alternateScreen = true;
break;
case 1049:
// Use Alternate Screen Buffer (ignored).
// Save the cursor as DECSC does, then use Alternate Screen Buffer.
text.enableAlternateScreen(true, true);
alternateScreen = true;
break;
case 1048:
// Save cursor, as ESC 7 does.
saveCursor();
break;
default:
Logger.log("Unsupported command parameter: CSI ?" + param + 'h'); //$NON-NLS-1$
Expand All @@ -1291,10 +1328,20 @@ private void processDecPrivateCommand_l() {
break;
case 47:
case 1047:
case 1048:
// Use Normal Screen Buffer, putting back what was on it, the cursor
// staying where the program left it. Leaving also resets the margins,
// which a repeated request must not do to the normal screen.
text.enableAlternateScreen(false, false);
alternateScreen = false;
break;
case 1049:
// Use Normal Screen Buffer (ignored, but reset scroll region).
text.setScrollRegion(-1, -1);
// Use Normal Screen Buffer and restore the cursor saved on the way in.
text.enableAlternateScreen(false, true);
alternateScreen = false;
break;
case 1048:
// Restore cursor, as ESC 8 does.
restoreCursor();
break;
default:
Logger.log("Unsupported command parameter: CSI ?" + param + 'l'); //$NON-NLS-1$
Expand Down Expand Up @@ -1561,6 +1608,11 @@ private void moveCursorBackward(int columnsToMove) {
*/
public void resetState() {
ansiState = ANSISTATE_INITIAL;
// a new connection starts on the normal screen, even if the last one ended
// while a full screen program had the alternate one; first, as leaving it puts
// back the shell's rendition, which the reset then resets
text.enableAlternateScreen(false);
alternateScreen = false;
text.setStyle(text.getDefaultStyle());
text.setScrollRegion(-1, -1);
text.setInsertMode(false);
Expand Down
Loading
Loading