From ea401e1f58ca5a088ac5d5e1d7963f36269afb76 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 18 Apr 2020 19:16:13 -0700 Subject: [PATCH] term: add implicit SGR reset when switching alt screen This was a bit of a pain to track down because this behavior isn't specified anywhere or called out explicitly. The issue is that if you use a true color escape sequence such as ```bash printf "\x1b[38;2;255;100;0mTRUECOLOR\n" ``` the active color would remain active when switching between the primary and the alt screen until something (eg: `ls --color`) changed it again. I hadn't run into this because in my prompt, many many years ago, I had it set to perform an SGR reset (`\x1b[0m`) as the first thing to ensure that the shell is in a saner state. For users that don't do this they end up with a weird looking color bleed effect. refs: https://github.com/wez/wezterm/issues/169 --- term/src/terminalstate.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index 2e643e6aa..53287758d 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -1123,6 +1123,7 @@ impl TerminalState { )) => { if !self.screen.is_alt_screen_active() { self.screen.activate_alt_screen(); + self.pen = CellAttributes::default(); } } Mode::ResetDecPrivateMode(DecPrivateMode::Code( @@ -1130,6 +1131,7 @@ impl TerminalState { )) => { if self.screen.is_alt_screen_active() { self.screen.activate_primary_screen(); + self.pen = CellAttributes::default(); } } @@ -1195,6 +1197,7 @@ impl TerminalState { self.save_cursor(); self.screen.activate_alt_screen(); self.set_cursor_pos(&Position::Absolute(0), &Position::Absolute(0)); + self.pen = CellAttributes::default(); self.erase_in_display(EraseInDisplay::EraseDisplay); } } @@ -1204,6 +1207,7 @@ impl TerminalState { if self.screen.is_alt_screen_active() { self.screen.activate_primary_screen(); self.restore_cursor(); + self.pen = CellAttributes::default(); } } Mode::SaveDecPrivateMode(DecPrivateMode::Code(_))