Skip to content

Commit a5de3d3

Browse files
committed
Fixed: Use current bg color when scrolling with horizontal margins
Fixes termux/termux-packages#12556 Issue was also reported here: https://www.reddit.com/r/termux/comments/1df1dii/how_can_i_fix_this_annoying_screenfilling_thing/
1 parent 57e4ef4 commit a5de3d3

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -2092,13 +2092,14 @@ private void setCursorPosition(int x, int y) {
20922092

20932093
private void scrollDownOneLine() {
20942094
mScrollCounter++;
2095+
long currentStyle = getStyle();
20952096
if (mLeftMargin != 0 || mRightMargin != mColumns) {
20962097
// Horizontal margin: Do not put anything into scroll history, just non-margin part of screen up.
20972098
mScreen.blockCopy(mLeftMargin, mTopMargin + 1, mRightMargin - mLeftMargin, mBottomMargin - mTopMargin - 1, mLeftMargin, mTopMargin);
20982099
// .. and blank bottom row between margins:
2099-
mScreen.blockSet(mLeftMargin, mBottomMargin - 1, mRightMargin - mLeftMargin, 1, ' ', mEffect);
2100+
mScreen.blockSet(mLeftMargin, mBottomMargin - 1, mRightMargin - mLeftMargin, 1, ' ', currentStyle);
21002101
} else {
2101-
mScreen.scrollDownOneLine(mTopMargin, mBottomMargin, getStyle());
2102+
mScreen.scrollDownOneLine(mTopMargin, mBottomMargin, currentStyle);
21022103
}
21032104
}
21042105

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

+27
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,31 @@ public void testScrollRegionDoesNotLimitCursorMovement() {
127127
" xxx"
128128
);
129129
}
130+
131+
/**
132+
* See <a href="https://github.com/termux/termux-packages/issues/12556">reported issue</a>.
133+
*/
134+
public void testClearingWhenScrollingWithMargins() {
135+
int newForeground = 2;
136+
int newBackground = 3;
137+
int size = 3;
138+
TerminalTestCase terminal = withTerminalSized(size, size)
139+
// Enable horizontal margin and set left margin to 1:
140+
.enterString("\033[?69h\033[2s")
141+
// Set foreground and background color:
142+
.enterString("\033[" + (30 + newForeground) + ";" + (40 + newBackground) + "m")
143+
// Enter newlines to scroll down:
144+
.enterString("\r\n\r\n\r\n\r\n\r\n");
145+
for (int row = 0; row < size; row++) {
146+
for (int col = 0; col < size; col++) {
147+
// The first column (outside of the scrolling area, due to us setting a left scroll
148+
// margin of 1) should be unmodified, the others should use the current style:
149+
int expectedForeground = col == 0 ? TextStyle.COLOR_INDEX_FOREGROUND : newForeground;
150+
int expectedBackground = col == 0 ? TextStyle.COLOR_INDEX_BACKGROUND : newBackground;
151+
terminal.assertForegroundColorAt(row, col, expectedForeground);
152+
terminal.assertBackgroundColorAt(row, col, expectedBackground);
153+
}
154+
}
155+
}
156+
130157
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ public void assertForegroundColorAt(int externalRow, int column, int color) {
301301
assertEquals(color, TextStyle.decodeForeColor(style));
302302
}
303303

304+
public void assertBackgroundColorAt(int externalRow, int column, int color) {
305+
long style = mTerminal.getScreen().mLines[mTerminal.getScreen().externalToInternalRow(externalRow)].getStyle(column);
306+
assertEquals(color, TextStyle.decodeBackColor(style));
307+
}
308+
304309
public TerminalTestCase assertColor(int colorIndex, int expected) {
305310
int actual = mTerminal.mColors.mCurrentColors[colorIndex];
306311
if (expected != actual) {

0 commit comments

Comments
 (0)