From a5de3d3a2bdaeff8c37c8df61059ae759a28a406 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 13 Aug 2024 14:27:23 +0200 Subject: [PATCH] Fixed: Use current bg color when scrolling with horizontal margins Fixes https://github.com/termux/termux-packages/issues/12556 Issue was also reported here: https://www.reddit.com/r/termux/comments/1df1dii/how_can_i_fix_this_annoying_screenfilling_thing/ --- .../com/termux/terminal/TerminalEmulator.java | 5 ++-- .../com/termux/terminal/ScrollRegionTest.java | 27 +++++++++++++++++++ .../com/termux/terminal/TerminalTestCase.java | 5 ++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java b/terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java index aeef393c62..6cf06b6c19 100644 --- a/terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java +++ b/terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java @@ -2092,13 +2092,14 @@ private void setCursorPosition(int x, int y) { private void scrollDownOneLine() { mScrollCounter++; + long currentStyle = getStyle(); if (mLeftMargin != 0 || mRightMargin != mColumns) { // Horizontal margin: Do not put anything into scroll history, just non-margin part of screen up. mScreen.blockCopy(mLeftMargin, mTopMargin + 1, mRightMargin - mLeftMargin, mBottomMargin - mTopMargin - 1, mLeftMargin, mTopMargin); // .. and blank bottom row between margins: - mScreen.blockSet(mLeftMargin, mBottomMargin - 1, mRightMargin - mLeftMargin, 1, ' ', mEffect); + mScreen.blockSet(mLeftMargin, mBottomMargin - 1, mRightMargin - mLeftMargin, 1, ' ', currentStyle); } else { - mScreen.scrollDownOneLine(mTopMargin, mBottomMargin, getStyle()); + mScreen.scrollDownOneLine(mTopMargin, mBottomMargin, currentStyle); } } diff --git a/terminal-emulator/src/test/java/com/termux/terminal/ScrollRegionTest.java b/terminal-emulator/src/test/java/com/termux/terminal/ScrollRegionTest.java index cc01c0454b..5d2679c513 100644 --- a/terminal-emulator/src/test/java/com/termux/terminal/ScrollRegionTest.java +++ b/terminal-emulator/src/test/java/com/termux/terminal/ScrollRegionTest.java @@ -127,4 +127,31 @@ public void testScrollRegionDoesNotLimitCursorMovement() { " xxx" ); } + + /** + * See reported issue. + */ + public void testClearingWhenScrollingWithMargins() { + int newForeground = 2; + int newBackground = 3; + int size = 3; + TerminalTestCase terminal = withTerminalSized(size, size) + // Enable horizontal margin and set left margin to 1: + .enterString("\033[?69h\033[2s") + // Set foreground and background color: + .enterString("\033[" + (30 + newForeground) + ";" + (40 + newBackground) + "m") + // Enter newlines to scroll down: + .enterString("\r\n\r\n\r\n\r\n\r\n"); + for (int row = 0; row < size; row++) { + for (int col = 0; col < size; col++) { + // The first column (outside of the scrolling area, due to us setting a left scroll + // margin of 1) should be unmodified, the others should use the current style: + int expectedForeground = col == 0 ? TextStyle.COLOR_INDEX_FOREGROUND : newForeground; + int expectedBackground = col == 0 ? TextStyle.COLOR_INDEX_BACKGROUND : newBackground; + terminal.assertForegroundColorAt(row, col, expectedForeground); + terminal.assertBackgroundColorAt(row, col, expectedBackground); + } + } + } + } diff --git a/terminal-emulator/src/test/java/com/termux/terminal/TerminalTestCase.java b/terminal-emulator/src/test/java/com/termux/terminal/TerminalTestCase.java index eb1da8c094..1d0b0271bb 100644 --- a/terminal-emulator/src/test/java/com/termux/terminal/TerminalTestCase.java +++ b/terminal-emulator/src/test/java/com/termux/terminal/TerminalTestCase.java @@ -301,6 +301,11 @@ public void assertForegroundColorAt(int externalRow, int column, int color) { assertEquals(color, TextStyle.decodeForeColor(style)); } + public void assertBackgroundColorAt(int externalRow, int column, int color) { + long style = mTerminal.getScreen().mLines[mTerminal.getScreen().externalToInternalRow(externalRow)].getStyle(column); + assertEquals(color, TextStyle.decodeBackColor(style)); + } + public TerminalTestCase assertColor(int colorIndex, int expected) { int actual = mTerminal.mColors.mCurrentColors[colorIndex]; if (expected != actual) {