From c54548df7e293f2d24dd04bfe2eae95fb163acfb Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 29 May 2023 15:59:04 -0700 Subject: [PATCH] Fix ClearToEndOfLine in last column when wrap_next=true MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Given a sequence like this, where the `ESC [ K` sequence is emitted at the last column when wrap_next=true: \u001b[47;30m  17:24:50 \u001b[0m\u001b[K rather than treating the column as out of bounds, we'd clear the final cell. refs: #3548 --- docs/changelog.md | 3 +++ term/src/terminalstate/mod.rs | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 4de13d634..07cea2566 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -98,6 +98,9 @@ As features stabilize some brief notes about them will accumulate here. overwritten due to a conpty issue. #3531 * Changing the color palette back to the default without resetting the terminal would prevent changes to `color_scheme` from taking effect. #3685 +* ClearToEndOfLine performed in the last column of the display, when it is + prepped to wrap to the next line, would incorrectly clear the last cell. + #3548 #### Updated * Bundled harfbuzz to 7.1.0 diff --git a/term/src/terminalstate/mod.rs b/term/src/terminalstate/mod.rs index a6a56921a..d7a1fab2c 100644 --- a/term/src/terminalstate/mod.rs +++ b/term/src/terminalstate/mod.rs @@ -2125,7 +2125,13 @@ impl TerminalState { let cols = self.screen().physical_cols; let bidi_mode = self.get_bidi_mode(); let range = match erase { - EraseInLine::EraseToEndOfLine => cx..cols, + // If wrap_next is true, then cx is effectively 1 column to the right. + // It feels wrong to handle this here, but in trying to centralize + // the logic for updating the cursor position, it causes regressions + // in the test suite. + // So this is here for now until a better solution is found. + // + EraseInLine::EraseToEndOfLine => cx + if self.wrap_next { 1 } else { 0 }..cols, EraseInLine::EraseToStartOfLine => 0..cx + 1, EraseInLine::EraseLine => 0..cols, };