diff --git a/app/src/terminal/grid_renderer.rs b/app/src/terminal/grid_renderer.rs index 817a156b0..31f6601db 100644 --- a/app/src/terminal/grid_renderer.rs +++ b/app/src/terminal/grid_renderer.rs @@ -1134,6 +1134,11 @@ fn render_grid_with_ligatures<'a>( None => { // If there are no non-empty cells in the entire row, we can skip it entirely if marked_text.peek().is_none() { + if let Some(sampler) = bg_color_sampler.as_deref_mut() { + for _ in 0..grid.columns() { + sampler.sample(ColorU::transparent_black()); + } + } continue; } grid.columns() - 1 diff --git a/app/src/terminal/model/terminal_model.rs b/app/src/terminal/model/terminal_model.rs index 7a62fb975..31ff3608d 100644 --- a/app/src/terminal/model/terminal_model.rs +++ b/app/src/terminal/model/terminal_model.rs @@ -2049,8 +2049,10 @@ impl TerminalModel { .active_block_mut() .set_saved_cursor(block_list_cursor); - // Reset alt screen contents. - let bg = self.alt_screen.grid_storage().cursor().template.bg; + // Reset alt screen contents. DECSET 1049 starts with a fresh + // alternate buffer; a transient SGR background from UI chrome like + // tmux's status line should not seed the entire pane. + let bg = ansi::Color::Named(ansi::NamedColor::Background); self.alt_screen .grid_storage_mut() .region_mut(..) diff --git a/app/src/terminal/model/terminal_model_test.rs b/app/src/terminal/model/terminal_model_test.rs index 06cb31bc2..a9214834d 100644 --- a/app/src/terminal/model/terminal_model_test.rs +++ b/app/src/terminal/model/terminal_model_test.rs @@ -650,6 +650,31 @@ fn test_alt_screen_toggle() { assert!(!terminal.alt_screen_active); } +#[test] +fn test_enter_alt_screen_clears_with_default_background() { + let mut terminal = TerminalModel::mock(None, None); + + terminal.terminal_attribute(ansi::Attr::Background(ansi::Color::Named( + ansi::NamedColor::Green, + ))); + terminal.set_mode(ansi::Mode::SwapScreen { + save_cursor_and_clear_screen: true, + }); + + let grid = terminal.alt_screen().grid_handler(); + for row in 0..grid.visible_rows() { + let row = grid.row(row).expect("visible row should exist"); + for cell in &row[..] { + assert_eq!(cell.c, '\0'); + assert_eq!( + cell.bg, + ansi::Color::Named(ansi::NamedColor::Background), + "alternate screen should not inherit transient primary-screen SGR background" + ); + } + } +} + #[test] fn test_reset_state() { let mut terminal: TerminalModel = TerminalModel::mock(None, None);