Skip to content

Commit

Permalink
Add support for CSI CHT (repeated tabs)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Aug 9, 2018
1 parent f8e0616 commit 8a5e612
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
40 changes: 26 additions & 14 deletions iTerm2XCTests/VT100CSIParserTest.m
Expand Up @@ -68,31 +68,27 @@ - (void)testSimpleCSI {
XCTAssert(token->type == VT100CSI_CUB);
XCTAssert(token.csi->count == 1);
XCTAssert(token.csi->p[0] == 1); // Default
XCTAssert(token.csi->subCount[0] == 0);
}

- (void)testSimpleCSIWithParameter {
VT100Token *token = [self tokenForDataWithFormat:@"%c[2D", VT100CC_ESC];
XCTAssert(token->type == VT100CSI_CUB);
XCTAssert(token.csi->count == 1);
XCTAssert(token.csi->p[0] == 2); // Parameter
XCTAssert(token.csi->subCount[0] == 0);
}

- (void)testSimpleCSIWithTwoDigitParameter {
VT100Token *token = [self tokenForDataWithFormat:@"%c[23D", VT100CC_ESC];
XCTAssert(token->type == VT100CSI_CUB);
XCTAssert(token.csi->count == 1);
XCTAssert(token.csi->p[0] == 23); // Parameter
XCTAssert(token.csi->subCount[0] == 0);
}

- (void)testParameterPrefix {
VT100Token *token = [self tokenForDataWithFormat:@"%c[>23c", VT100CC_ESC];
XCTAssert(token->type == VT100CSI_DA2);
XCTAssert(token.csi->count == 1);
XCTAssert(token.csi->p[0] == 23); // Parameter
XCTAssert(token.csi->subCount[0] == 0);
}

- (void)testTwoParameters {
Expand All @@ -101,22 +97,39 @@ - (void)testTwoParameters {
XCTAssert(token.csi->count == 2);
XCTAssert(token.csi->p[0] == 5);
XCTAssert(token.csi->p[1] == 6);
XCTAssert(token.csi->subCount[0] == 0);
}

- (void)testCursorForwardTabulation {
VT100Token *token = [self tokenForDataWithFormat:@"%c[2I", VT100CC_ESC];
XCTAssert(token->type == VT100CSI_CHT);
XCTAssert(token.csi->count == 1);
XCTAssert(token.csi->p[0] == 2);
}

- (void)testCursorForwardTabulationDefault {
VT100Token *token = [self tokenForDataWithFormat:@"%c[I", VT100CC_ESC];
XCTAssert(token->type == VT100CSI_CHT);
XCTAssert(token.csi->count == 1);
XCTAssert(token.csi->p[0] == 1);
}

- (void)testSubParameter {
VT100Token *token = [self tokenForDataWithFormat:@"%c[38:2:255:128:64:0:5:1m", VT100CC_ESC];
XCTAssert(token->type == VT100CSI_SGR);
XCTAssert(token.csi->count == 1);
XCTAssert(token.csi->p[0] == 38);
XCTAssert(token.csi->subCount[0] == 7);
XCTAssert(token.csi->sub[0][0] == 2);
XCTAssert(token.csi->sub[0][1] == 255);
XCTAssert(token.csi->sub[0][2] == 128);
XCTAssert(token.csi->sub[0][3] == 64);
XCTAssert(token.csi->sub[0][4] == 0);
XCTAssert(token.csi->sub[0][5] == 5);
XCTAssert(token.csi->sub[0][6] == 1);

int subs[VT100CSISUBPARAM_MAX];
int numberOfSubparameters = iTermParserGetAllCSISubparametersForParameter(token.csi, 0, subs);

XCTAssert(numberOfSubparameters == 7);
XCTAssert(subs[0] == 2);
XCTAssert(subs[1] == 255);
XCTAssert(subs[2] == 128);
XCTAssert(subs[3] == 64);
XCTAssert(subs[4] == 0);
XCTAssert(subs[5] == 5);
XCTAssert(subs[6] == 1);
}

- (void)testBogusCharacterInParameters {
Expand All @@ -131,7 +144,6 @@ - (void)testIntermediateByte {
XCTAssert(token->type == VT100CSI_DECSCUSR);
XCTAssert(token.csi->count == 1);
XCTAssert(token.csi->p[0] == 3);
XCTAssert(token.csi->subCount[0] == 0);
}

- (void)testBogusCharInParameterSection {
Expand Down
5 changes: 5 additions & 0 deletions sources/VT100CSIParser.m
Expand Up @@ -427,6 +427,11 @@ static void SetCSITypeAndDefaultParameters(CSIParam *param, VT100Token *result)
iTermParserSetCSIParameterIfDefault(param, 1, 1);
break;

case 'I':
result->type = VT100CSI_CHT;
iTermParserSetCSIParameterIfDefault(param, 0, 1);
break;

case 'c':
result->type = VT100CSI_DA;
iTermParserSetCSIParameterIfDefault(param, 0, 0);
Expand Down
5 changes: 5 additions & 0 deletions sources/VT100Terminal.m
Expand Up @@ -1377,6 +1377,11 @@ - (void)executeToken:(VT100Token *)token {
case VT100CSI_CUP:
[delegate_ terminalMoveCursorToX:token.csi->p[1] y:token.csi->p[0]];
break;
case VT100CSI_CHT:
for (int i = 0; i < token.csi->p[0]; i++) {
[delegate_ terminalAppendTabAtCursor:!_softAlternateScreenMode];
}
break;
case VT100CSI_CUU:
[delegate_ terminalCursorUp:token.csi->p[0] > 0 ? token.csi->p[0] : 1
andToStartOfLine:NO];
Expand Down
1 change: 1 addition & 0 deletions sources/VT100Token.h
Expand Up @@ -54,6 +54,7 @@ typedef enum {
VT100CSI_CUD, // Cursor Down
VT100CSI_CUF, // Cursor Forward
VT100CSI_CUP, // Cursor Position
VT100CSI_CHT, // Cursor Forward Tabulation Ps tab stops
VT100CSI_CUU, // Cursor Up
VT100CSI_CNL, // Cursor Next Line
VT100CSI_CPL, // Cursor Preceding Line
Expand Down
1 change: 1 addition & 0 deletions sources/VT100Token.m
Expand Up @@ -122,6 +122,7 @@ - (NSString *)codeName {
@(VT100CSI_CUD): @"VT100CSI_CUD",
@(VT100CSI_CUF): @"VT100CSI_CUF",
@(VT100CSI_CUP): @"VT100CSI_CUP",
@(VT100CSI_CHT): @"VT100CSI_CHT",
@(VT100CSI_CUU): @"VT100CSI_CUU",
@(VT100CSI_DA): @"VT100CSI_DA",
@(VT100CSI_DA2): @"VT100CSI_DA2",
Expand Down
20 changes: 20 additions & 0 deletions tests/CHT.txt
@@ -0,0 +1,20 @@
Back tab by 1:
01234567890123456789_

Back tab by 2:
01234567890123456789_

Back tab by 99:
012345678901234567899

Regular tab:
01234567890123456789 _

Default CHT:
01234567890123456789_

CHT 2:
01234567890123456789_

CHT 99:
01234567890123456789_

0 comments on commit 8a5e612

Please sign in to comment.