Skip to content

Commit

Permalink
Add support for ESC[#X to VT100
Browse files Browse the repository at this point in the history
This escape sequence can be generated when using Powershell on
Windows (and possibly other places too) to erase number of
characters.

Change-Id: I32405f51a3f91fd8653d44f2676a5c85b696ef99
  • Loading branch information
coehlrich authored and jonahgraham committed Aug 19, 2023
1 parent 808147e commit 3240494
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,11 @@ public interface IVT100EmulatorBackend {
* scroll region.
*/
void processReverseLineFeed();

/**
* Replaces characters from the cursor position with space characters.
*
* @param n number of characters to replace
*/
void eraseCharacters(int n);
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,9 @@ public void processReverseLineFeed() {
fBackend.processReverseLineFeed();
}

@Override
public void eraseCharacters(int n) {
fWriter.println("eraseCharacters(" + n + ")"); //$NON-NLS-1$ //$NON-NLS-2$
fBackend.eraseCharacters(n);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,7 @@ private void processAnsiCommandCharacter(char ansiCommandCharacter) {

case 'X':
// Erase character.
// Emacs, vi, and GNU readline don't seem to use this command, so we ignore
// it for now.
processAnsiCommand_X();
break;

case 'Z':
Expand Down Expand Up @@ -1238,6 +1237,13 @@ private void processAnsiCommand_T() {
text.scrollDown(getAnsiParameter(0));
}

/**
* Erases n characters from cursor (default = 1 character)
*/
private void processAnsiCommand_X() {
text.eraseCharacters(getAnsiParameter(0));
}

private void processDecPrivateCommand_h() {
int param = getAnsiParameter(0);
switch (param) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,15 @@ public void scrollDown(int n) {
fTerminal.scroll(line, nLines, n);
}
}

@Override
public void eraseCharacters(int n) {
synchronized (fTerminal) {
int line = toAbsoluteLine(fCursorLine);
int end = Math.min(fCursorColumn + n, fColumns);
for (int col = fCursorColumn; col < end; col++) {
fTerminal.setChar(line, col, '\000', null);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -926,4 +926,24 @@ public void testScrollRegion() {
assertEquals("ghi", new String(term.getChars(5)));
}

public void testEraseCharacters() {
ITerminalTextData term = makeITerminalTextData();
IVT100EmulatorBackend vt100 = makeBakend(term);
vt100.setDimensions(4, 4);
String s = "aaaa\n" + "bcde\n" + "1234\n" + "5678";
fill(term, s);
vt100.setCursor(0, 0);
vt100.eraseCharacters(1);
assertEqualsTerm(" aaa\n" + "bcde\n" + "1234\n" + "5678", toMultiLineText(term));

fill(term, s);
vt100.setCursor(1, 0);
vt100.eraseCharacters(1);
assertEqualsTerm("aaaa\n" + " cde\n" + "1234\n" + "5678", toMultiLineText(term));

fill(term, s);
vt100.setCursor(2, 1);
vt100.eraseCharacters(2);
assertEqualsTerm("aaaa\n" + "bcde\n" + "1 4\n" + "5678", toMultiLineText(term));
}
}

0 comments on commit 3240494

Please sign in to comment.