Skip to content

Commit d90e3fb

Browse files
evg-zhabotinskyfornwall
authored andcommitted
Fixed: Make ScrollDown escape respect margins
SD sequence (`${CSI}${N}T`) was scrolling the whole width of the terminal instead of just between the margins. RI sequence (`${ESC}M`, move cursor up 1 line) was doing the same. Fixed that. Fixes #2576 where in tmux scrolling one of several side-by-side panels down resulted in all visually scrolling.
1 parent 245158c commit d90e3fb

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,8 +1418,8 @@ private void doEsc(int b) {
14181418
// http://www.vt100.net/docs/vt100-ug/chapter3.html: "Move the active position to the same horizontal
14191419
// position on the preceding line. If the active position is at the top margin, a scroll down is performed".
14201420
if (mCursorRow <= mTopMargin) {
1421-
mScreen.blockCopy(0, mTopMargin, mColumns, mBottomMargin - (mTopMargin + 1), 0, mTopMargin + 1);
1422-
blockClear(0, mTopMargin, mColumns);
1421+
mScreen.blockCopy(mLeftMargin, mTopMargin, mRightMargin - mLeftMargin, mBottomMargin - (mTopMargin + 1), mLeftMargin, mTopMargin + 1);
1422+
blockClear(mLeftMargin, mTopMargin, mRightMargin - mLeftMargin);
14231423
} else {
14241424
mCursorRow--;
14251425
}
@@ -1628,8 +1628,8 @@ private void doCsi(int b) {
16281628
final int linesToScrollArg = getArg0(1);
16291629
final int linesBetweenTopAndBottomMargins = mBottomMargin - mTopMargin;
16301630
final int linesToScroll = Math.min(linesBetweenTopAndBottomMargins, linesToScrollArg);
1631-
mScreen.blockCopy(0, mTopMargin, mColumns, linesBetweenTopAndBottomMargins - linesToScroll, 0, mTopMargin + linesToScroll);
1632-
blockClear(0, mTopMargin, mColumns, linesToScroll);
1631+
mScreen.blockCopy(mLeftMargin, mTopMargin, mRightMargin - mLeftMargin, linesBetweenTopAndBottomMargins - linesToScroll, mLeftMargin, mTopMargin + linesToScroll);
1632+
blockClear(mLeftMargin, mTopMargin, mRightMargin - mLeftMargin, linesToScroll);
16331633
} else {
16341634
// "${CSI}${func};${startx};${starty};${firstrow};${lastrow}T" - initiate highlight mouse tracking.
16351635
unimplementedSequence(b);

terminal-emulator/src/test/java/com/termux/terminal/ScrollRegionTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public void testNELRespectsLeftMargin() {
7575
withTerminalSized(3, 3).enterString("\033[?69h\033[2sABC\033[?6h\033ED").assertLinesAre("ABC", " D ", " ");
7676
}
7777

78+
public void testRiRespectsLeftMargin() {
79+
// Reverse Index (RI), ${ESC}M, should respect horizontal margins:
80+
withTerminalSized(4, 3).enterString("ABCD\033[?69h\033[2;3s\033[?6h\033M").assertLinesAre("A D", " BC ", " ");
81+
}
82+
83+
public void testSdRespectsLeftMargin() {
84+
// Scroll Down (SD), ${CSI}${N}T, should respect horizontal margins:
85+
withTerminalSized(4, 3).enterString("ABCD\033[?69h\033[2;3s\033[?6h\033[2T").assertLinesAre("A D", " ", " BC ");
86+
}
87+
7888
public void testBackwardIndex() {
7989
// vttest "Menu 11.3.2: VT420 Cursor-Movement Test", test 7.
8090
// Without margins:

0 commit comments

Comments
 (0)