feat(tui): simplify terminal resize reflow replay

Use the standard viewport-aware history insertion path for resize reflow instead of the temporary direct/prefill replay modes. This keeps terminal-specific max_rows caps while removing the experimental replay-mode config and queue plumbing.
This commit is contained in:
Felipe Coury
2026-04-24 13:02:13 -03:00
parent 58af37c058
commit 036d15fa1b
12 changed files with 28 additions and 476 deletions
-17
View File
@@ -534,19 +534,6 @@ pub struct ModelAvailabilityNuxConfig {
pub const DEFAULT_TERMINAL_RESIZE_REFLOW_FALLBACK_MAX_ROWS: usize = 1_000;
/// How resize reflow should rebuild terminal scrollback during this experimental phase.
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Default, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum TerminalResizeReflowReplayModeToml {
/// Rebuild scrollback through the same viewport-aware insertion path used during startup.
#[default]
Standard,
/// Rebuild scrollback using transcript rows directly, without extra blank prefill rows.
Direct,
/// Rebuild scrollback after reserving blank rows for terminals that need viewport prefill.
Prefill,
}
/// Experimental terminal resize-reflow tuning knobs.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default, JsonSchema)]
#[schemars(deny_unknown_fields)]
@@ -557,10 +544,6 @@ pub struct TerminalResizeReflowToml {
#[serde(default)]
#[schemars(range(min = 0))]
pub max_rows: Option<usize>,
/// Temporary testing knob for selecting the terminal scrollback replay strategy.
#[serde(default)]
pub replay_mode: TerminalResizeReflowReplayModeToml,
}
/// Collection of settings that are specific to the TUI.
+1 -37
View File
@@ -1933,32 +1933,6 @@
},
"type": "object"
},
"TerminalResizeReflowReplayModeToml": {
"description": "How resize reflow should rebuild terminal scrollback during this experimental phase.",
"oneOf": [
{
"description": "Rebuild scrollback through the same viewport-aware insertion path used during startup.",
"enum": [
"standard"
],
"type": "string"
},
{
"description": "Rebuild scrollback using transcript rows directly, without extra blank prefill rows.",
"enum": [
"direct"
],
"type": "string"
},
{
"description": "Rebuild scrollback after reserving blank rows for terminals that need viewport prefill.",
"enum": [
"prefill"
],
"type": "string"
}
]
},
"TerminalResizeReflowToml": {
"additionalProperties": false,
"description": "Experimental terminal resize-reflow tuning knobs.",
@@ -1969,15 +1943,6 @@
"format": "uint",
"minimum": 0.0,
"type": "integer"
},
"replay_mode": {
"allOf": [
{
"$ref": "#/definitions/TerminalResizeReflowReplayModeToml"
}
],
"default": "standard",
"description": "Temporary testing knob for selecting the terminal scrollback replay strategy."
}
},
"type": "object"
@@ -2119,8 +2084,7 @@
}
],
"default": {
"max_rows": null,
"replay_mode": "standard"
"max_rows": null
},
"description": "Experimental terminal resize-reflow tuning knobs."
},
+1 -70
View File
@@ -43,7 +43,6 @@ use codex_config::types::NotificationMethod;
use codex_config::types::Notifications;
use codex_config::types::SandboxWorkspaceWrite;
use codex_config::types::SkillsConfig;
use codex_config::types::TerminalResizeReflowReplayModeToml;
use codex_config::types::TerminalResizeReflowToml;
use codex_config::types::ToolSuggestDiscoverableType;
use codex_config::types::Tui;
@@ -519,48 +518,10 @@ max_rows = 9000
.terminal_resize_reflow,
TerminalResizeReflowToml {
max_rows: Some(9000),
replay_mode: TerminalResizeReflowReplayModeToml::Standard,
}
);
}
#[test]
fn config_toml_deserializes_terminal_resize_reflow_replay_mode() {
for (value, expected) in [
("standard", TerminalResizeReflowReplayModeToml::Standard),
("direct", TerminalResizeReflowReplayModeToml::Direct),
("prefill", TerminalResizeReflowReplayModeToml::Prefill),
] {
let cfg: ConfigToml = toml::from_str(&format!(
r#"
[tui.terminal_resize_reflow]
replay_mode = "{value}"
"#,
))
.expect("TOML deserialization should succeed for resize reflow replay mode");
assert_eq!(
cfg.tui
.expect("tui config should deserialize")
.terminal_resize_reflow
.replay_mode,
expected
);
}
}
#[test]
fn config_toml_rejects_invalid_terminal_resize_reflow_replay_mode() {
let result = toml::from_str::<ConfigToml>(
r#"
[tui.terminal_resize_reflow]
replay_mode = "unknown"
"#,
);
assert!(result.is_err());
}
#[tokio::test]
async fn runtime_config_defaults_model_availability_nux() {
let cfg = Config::load_from_base_config_with_overrides(
@@ -1378,17 +1339,12 @@ async fn runtime_config_resolves_terminal_resize_reflow_defaults_and_overrides()
cfg.terminal_resize_reflow.max_rows,
TerminalResizeReflowMaxRows::Auto
);
assert_eq!(
cfg.terminal_resize_reflow.replay_mode,
TerminalResizeReflowReplayMode::Standard
);
let cfg = Config::load_from_base_config_with_overrides(
ConfigToml {
tui: Some(Tui {
terminal_resize_reflow: TerminalResizeReflowToml {
max_rows: Some(9000),
..Default::default()
},
..Default::default()
}),
@@ -1408,10 +1364,7 @@ async fn runtime_config_resolves_terminal_resize_reflow_defaults_and_overrides()
let cfg = Config::load_from_base_config_with_overrides(
ConfigToml {
tui: Some(Tui {
terminal_resize_reflow: TerminalResizeReflowToml {
max_rows: Some(0),
..Default::default()
},
terminal_resize_reflow: TerminalResizeReflowToml { max_rows: Some(0) },
..Default::default()
}),
..Default::default()
@@ -1426,28 +1379,6 @@ async fn runtime_config_resolves_terminal_resize_reflow_defaults_and_overrides()
cfg.terminal_resize_reflow.max_rows,
TerminalResizeReflowMaxRows::Disabled
);
let cfg = Config::load_from_base_config_with_overrides(
ConfigToml {
tui: Some(Tui {
terminal_resize_reflow: TerminalResizeReflowToml {
replay_mode: TerminalResizeReflowReplayModeToml::Prefill,
..Default::default()
},
..Default::default()
}),
..Default::default()
},
ConfigOverrides::default(),
tempdir().expect("tempdir").abs(),
)
.await
.expect("load config with prefill resize reflow replay mode");
assert_eq!(
cfg.terminal_resize_reflow.replay_mode,
TerminalResizeReflowReplayMode::Prefill
);
}
#[tokio::test]
-20
View File
@@ -636,18 +636,9 @@ pub enum TerminalResizeReflowMaxRows {
Limit(usize),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TerminalResizeReflowReplayMode {
#[default]
Standard,
Direct,
Prefill,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct TerminalResizeReflowConfig {
pub max_rows: TerminalResizeReflowMaxRows,
pub replay_mode: TerminalResizeReflowReplayMode,
}
impl AuthManagerConfig for Config {
@@ -1518,17 +1509,6 @@ fn resolve_terminal_resize_reflow_config(config_toml: &ConfigToml) -> TerminalRe
Some(rows) => TerminalResizeReflowMaxRows::Limit(rows),
None => TerminalResizeReflowMaxRows::Auto,
},
replay_mode: match tui.terminal_resize_reflow.replay_mode {
codex_config::types::TerminalResizeReflowReplayModeToml::Standard => {
TerminalResizeReflowReplayMode::Standard
}
codex_config::types::TerminalResizeReflowReplayModeToml::Direct => {
TerminalResizeReflowReplayMode::Direct
}
codex_config::types::TerminalResizeReflowReplayModeToml::Prefill => {
TerminalResizeReflowReplayMode::Prefill
}
},
}
}
+1 -1
View File
@@ -665,7 +665,7 @@ pub const FEATURES: &[FeatureSpec] = &[
menu_description: "Rebuild Codex-owned transcript scrollback when the terminal width changes.",
announcement: "",
},
default_enabled: false,
default_enabled: true,
},
FeatureSpec {
id: Feature::WebSearchRequest,
+4 -3
View File
@@ -32,7 +32,8 @@ fn default_enabled_features_are_stable() {
for spec in crate::FEATURES {
if spec.default_enabled {
assert!(
matches!(spec.stage, Stage::Stable | Stage::Removed),
matches!(spec.stage, Stage::Stable | Stage::Removed)
|| spec.id == Feature::TerminalResizeReflow,
"feature `{}` is enabled by default but is not stable/removed ({:?})",
spec.key,
spec.stage
@@ -139,7 +140,7 @@ fn request_permissions_tool_is_under_development() {
}
#[test]
fn terminal_resize_reflow_is_experimental_and_disabled_by_default() {
fn terminal_resize_reflow_is_experimental_and_enabled_by_default() {
assert_eq!(
feature_for_key("terminal_resize_reflow"),
Some(Feature::TerminalResizeReflow)
@@ -148,7 +149,7 @@ fn terminal_resize_reflow_is_experimental_and_disabled_by_default() {
Feature::TerminalResizeReflow.stage(),
Stage::Experimental { .. }
));
assert_eq!(Feature::TerminalResizeReflow.default_enabled(), false);
assert_eq!(Feature::TerminalResizeReflow.default_enabled(), true);
}
#[test]
+6 -10
View File
@@ -1159,16 +1159,12 @@ impl App {
let desired_height =
self.chat_widget.desired_height(tui.terminal.size()?.width);
if terminal_resize_reflow_active {
tui.draw_with_resize_reflow(
desired_height,
self.config.terminal_resize_reflow.replay_mode,
|frame| {
self.chat_widget.render(frame.area(), frame.buffer);
if let Some((x, y)) = self.chat_widget.cursor_pos(frame.area()) {
frame.set_cursor_position((x, y));
}
},
)?;
tui.draw_with_resize_reflow(desired_height, |frame| {
self.chat_widget.render(frame.area(), frame.buffer);
if let Some((x, y)) = self.chat_widget.cursor_pos(frame.area()) {
frame.set_cursor_position((x, y));
}
})?;
} else {
tui.draw(desired_height, |frame| {
self.chat_widget.render(frame.area(), frame.buffer);
@@ -671,7 +671,6 @@ mod tests {
r#"
[tui.terminal_resize_reflow]
max_rows = 9000
replay_mode = "prefill"
"#,
)?;
@@ -681,10 +680,6 @@ replay_mode = "prefill"
app.config.terminal_resize_reflow.max_rows,
crate::legacy_core::config::TerminalResizeReflowMaxRows::Limit(9000)
);
assert_eq!(
app.config.terminal_resize_reflow.replay_mode,
crate::legacy_core::config::TerminalResizeReflowReplayMode::Prefill
);
Ok(())
}
+9 -22
View File
@@ -22,7 +22,6 @@ use super::InitialHistoryReplayBuffer;
use super::trailing_run_start;
use crate::history_cell;
use crate::history_cell::HistoryCell;
use crate::legacy_core::config::TerminalResizeReflowReplayMode;
use crate::transcript_reflow::TRANSCRIPT_REFLOW_DEBOUNCE;
use crate::transcript_reflow::TranscriptReflowKind;
use crate::tui;
@@ -151,21 +150,16 @@ impl App {
crate::resize_reflow_cap::resize_reflow_max_rows(self.config.terminal_resize_reflow)
}
fn clear_terminal_for_full_resize_replay(&mut self, tui: &mut tui::Tui) -> Result<()> {
fn clear_terminal_for_resize_replay(&mut self, tui: &mut tui::Tui) -> Result<()> {
if tui.is_alt_screen_active() {
tui.terminal.clear_visible_screen()?;
} else {
tui.terminal.clear_scrollback_and_visible_screen_ansi()?;
}
if matches!(
self.config.terminal_resize_reflow.replay_mode,
TerminalResizeReflowReplayMode::Standard
) {
let mut area = tui.terminal.viewport_area;
if area.y > 0 {
area.y = 0;
tui.terminal.set_viewport_area(area);
}
let mut area = tui.terminal.viewport_area;
if area.y > 0 {
area.y = 0;
tui.terminal.set_viewport_area(area);
}
Ok(())
}
@@ -396,11 +390,11 @@ impl App {
// Drop any queued pre-resize/pre-consolidation inserts before rebuilding from cells.
tui.clear_pending_history_lines();
self.clear_terminal_for_full_resize_replay(tui)?;
self.clear_terminal_for_resize_replay(tui)?;
self.deferred_history_lines.clear();
if !reflowed_lines.is_empty() {
tui.insert_reflowed_history_lines(reflowed_lines);
tui.insert_history_lines(reflowed_lines);
}
Ok(width)
@@ -418,17 +412,10 @@ impl App {
let reflowed_lines = reflow_result.lines;
tui.clear_pending_history_lines();
if matches!(
self.config.terminal_resize_reflow.replay_mode,
TerminalResizeReflowReplayMode::Standard
) {
self.clear_terminal_for_full_resize_replay(tui)?;
} else {
tui.terminal.clear_visible_screen()?;
}
self.clear_terminal_for_resize_replay(tui)?;
self.deferred_history_lines.clear();
if !reflowed_lines.is_empty() {
tui.insert_reflowed_history_lines(reflowed_lines);
tui.insert_history_lines(reflowed_lines);
}
Ok(width)
+5 -142
View File
@@ -2,8 +2,7 @@
//!
//! Codex uses the terminal scrollback itself for finalized chat history, so inserting a history
//! cell is an escape-sequence operation rather than a normal ratatui render. The mode determines
//! whether new history may move the inline viewport or whether resize reflow should replay rows
//! through full-screen strategies while preserving the viewport chosen by the reflow draw path.
//! how to create room for new history above the inline viewport.
use std::fmt;
use std::io;
@@ -46,8 +45,6 @@ use ratatui::text::Span;
pub enum InsertHistoryMode {
Standard,
Zellij,
FullScreenReplayPrefill,
FullScreenReplayDirect,
}
impl InsertHistoryMode {
@@ -79,11 +76,8 @@ where
/// emits newlines at the screen bottom to create space (since Zellij ignores scroll
/// region escapes) and writes lines at computed absolute positions. Both modes
/// update `terminal.viewport_area` so subsequent draw passes know where the
/// viewport moved to. Resize reflow can also use those viewport-aware modes after
/// clearing old scrollback. In `FullScreenReplayPrefill` mode blank rows are used
/// to create scrollback space before replaying content, matching xterm.js behavior.
/// `FullScreenReplayDirect` keeps the no-prefill strategy isolated for terminals
/// where the prefilled blank rows become user-visible scrollback.
/// viewport moved to. Resize reflow uses the same viewport-aware path after
/// clearing old scrollback.
pub fn insert_history_lines_with_mode<B>(
terminal: &mut crate::custom_terminal::Terminal<B>,
lines: Vec<Line>,
@@ -130,13 +124,9 @@ where
let wrapped_lines = wrapped_rows as u16;
match mode {
InsertHistoryMode::Zellij | InsertHistoryMode::FullScreenReplayPrefill => {
InsertHistoryMode::Zellij => {
let space_below = screen_size.height.saturating_sub(area.bottom());
let shift_down = if matches!(mode, InsertHistoryMode::Zellij) {
wrapped_lines.min(space_below)
} else {
0
};
let shift_down = wrapped_lines.min(space_below);
let scroll_up_amount = wrapped_lines.saturating_sub(shift_down);
if scroll_up_amount > 0 {
@@ -164,33 +154,6 @@ where
}
write_history_line(writer, line, wrap_width)?;
}
if matches!(mode, InsertHistoryMode::FullScreenReplayPrefill) {
let reserve_rows = wrapped_lines
.min(screen_size.height)
.saturating_sub(area.top());
if reserve_rows > 0 {
queue!(
writer,
MoveTo(/*x*/ 0, screen_size.height.saturating_sub(1))
)?;
for _ in 0..reserve_rows {
queue!(writer, Print("\n"))?;
}
}
}
}
InsertHistoryMode::FullScreenReplayDirect => {
// Rebuild scrollback with transcript content itself. Pre-scrolling with blank
// newlines creates visible empty scrollback in terminals such as Terminal.app.
queue!(writer, MoveTo(/*x*/ 0, /*y*/ 0))?;
for (i, line) in wrapped.iter().enumerate() {
if i > 0 {
queue!(writer, Print("\r\n"))?;
}
write_history_line(writer, line, wrap_width)?;
}
}
InsertHistoryMode::Standard => {
let cursor_top = if area.bottom() < screen_size.height {
@@ -877,104 +840,4 @@ mod tests {
assert_eq!(term.viewport_area, Rect::new(0, 5, width, 2));
assert_eq!(term.visible_history_rows(), 1);
}
#[test]
fn vt100_full_screen_replay_preserves_viewport() {
let width: u16 = 32;
let height: u16 = 8;
let backend = VT100Backend::new(width, height);
let mut term = crate::custom_terminal::Terminal::with_options(backend).expect("terminal");
let viewport = Rect::new(/*x*/ 0, /*y*/ 4, width, /*height*/ 2);
term.set_viewport_area(viewport);
let lines: Vec<Line<'static>> = (0..12)
.map(|idx| Line::from(format!("reflow line {idx:02}")))
.collect();
insert_history_lines_with_mode(
&mut term,
lines,
InsertHistoryMode::FullScreenReplayPrefill,
)
.expect("insert reflow history");
let start_row = 0;
let rows: Vec<String> = term
.backend()
.vt100()
.screen()
.rows(start_row, width)
.collect();
assert!(
rows.iter().any(|row| row.contains("reflow line 11")),
"expected replayed history tail in screen output, rows: {rows:?}"
);
assert_eq!(term.viewport_area, viewport);
assert_eq!(term.visible_history_rows(), viewport.top());
}
#[test]
fn vt100_full_screen_replay_reserves_viewport_rows_for_tui() {
let width: u16 = 32;
let height: u16 = 8;
let backend = VT100Backend::new(width, height);
let mut term = crate::custom_terminal::Terminal::with_options(backend).expect("terminal");
let viewport = Rect::new(/*x*/ 0, /*y*/ 4, width, /*height*/ 3);
term.set_viewport_area(viewport);
let lines: Vec<Line<'static>> = (0..6)
.map(|idx| Line::from(format!("reflow line {idx:02}")))
.collect();
insert_history_lines_with_mode(
&mut term,
lines,
InsertHistoryMode::FullScreenReplayPrefill,
)
.expect("insert reflow history");
let rows: Vec<String> = term
.backend()
.vt100()
.screen()
.rows(/*start*/ 0, width)
.collect();
assert!(
rows[viewport.top() as usize - 1].contains("reflow line 05"),
"expected replayed tail immediately above viewport, rows: {rows:?}"
);
assert!(
rows[viewport.top() as usize..]
.iter()
.all(|row| !row.contains("reflow line")),
"expected replay not to occupy reserved viewport rows, rows: {rows:?}"
);
assert_eq!(term.viewport_area, viewport);
}
#[test]
fn vt100_full_screen_replay_direct_does_not_reserve_viewport_rows() {
let width: u16 = 32;
let height: u16 = 8;
let backend = VT100Backend::new(width, height);
let mut term = crate::custom_terminal::Terminal::with_options(backend).expect("terminal");
let viewport = Rect::new(/*x*/ 0, /*y*/ 4, width, /*height*/ 3);
term.set_viewport_area(viewport);
let lines: Vec<Line<'static>> = (0..6)
.map(|idx| Line::from(format!("reflow line {idx:02}")))
.collect();
insert_history_lines_with_mode(&mut term, lines, InsertHistoryMode::FullScreenReplayDirect)
.expect("insert reflow history");
let rows: Vec<String> = term
.backend()
.vt100()
.screen()
.rows(/*start*/ 0, width)
.collect();
assert!(
rows[viewport.top() as usize].contains("reflow line 04"),
"expected direct replay not to prefill blank viewport rows, rows: {rows:?}"
);
assert_eq!(term.viewport_area, viewport);
}
}
-2
View File
@@ -128,7 +128,6 @@ mod tests {
let terminal = test_terminal(TerminalName::VsCode);
let config = TerminalResizeReflowConfig {
max_rows: TerminalResizeReflowMaxRows::Limit(42),
..Default::default()
};
assert_eq!(
@@ -144,7 +143,6 @@ mod tests {
let terminal = test_terminal(TerminalName::VsCode);
let config = TerminalResizeReflowConfig {
max_rows: TerminalResizeReflowMaxRows::Disabled,
..Default::default()
};
assert_eq!(
+1 -147
View File
@@ -41,7 +41,6 @@ use tokio_stream::Stream;
pub use self::frame_requester::FrameRequester;
use crate::custom_terminal;
use crate::custom_terminal::Terminal as CustomTerminal;
use crate::legacy_core::config::TerminalResizeReflowReplayMode;
use crate::notifications::DesktopNotificationBackend;
use crate::notifications::detect_backend;
use crate::tui::event_stream::EventBroker;
@@ -174,34 +173,12 @@ fn should_emit_notification(condition: NotificationCondition, terminal_focused:
}
}
fn insert_history_mode_for_resize_reflow(
replay_mode: TerminalResizeReflowReplayMode,
is_zellij: bool,
) -> crate::insert_history::InsertHistoryMode {
match replay_mode {
TerminalResizeReflowReplayMode::Standard => {
crate::insert_history::InsertHistoryMode::new(is_zellij)
}
TerminalResizeReflowReplayMode::Direct => {
crate::insert_history::InsertHistoryMode::FullScreenReplayDirect
}
TerminalResizeReflowReplayMode::Prefill => {
crate::insert_history::InsertHistoryMode::FullScreenReplayPrefill
}
}
}
#[cfg(test)]
mod tests {
use super::ResizeReflowDrawRefresh;
use super::insert_history_mode_for_resize_reflow;
use super::keyboard_enhancement_disabled_for;
use super::parse_bool_env;
use super::resize_reflow_draw_refresh;
use super::should_emit_notification;
use super::vscode_terminal_detected;
use crate::insert_history::InsertHistoryMode;
use crate::legacy_core::config::TerminalResizeReflowReplayMode;
use codex_config::types::NotificationCondition;
#[test]
@@ -220,38 +197,6 @@ mod tests {
));
}
#[test]
fn resize_reflow_replay_mode_selects_insert_history_mode() {
assert_eq!(
insert_history_mode_for_resize_reflow(
TerminalResizeReflowReplayMode::Standard,
/*is_zellij*/ false,
),
InsertHistoryMode::Standard
);
assert_eq!(
insert_history_mode_for_resize_reflow(
TerminalResizeReflowReplayMode::Standard,
/*is_zellij*/ true,
),
InsertHistoryMode::Zellij
);
assert_eq!(
insert_history_mode_for_resize_reflow(
TerminalResizeReflowReplayMode::Direct,
/*is_zellij*/ false,
),
InsertHistoryMode::FullScreenReplayDirect
);
assert_eq!(
insert_history_mode_for_resize_reflow(
TerminalResizeReflowReplayMode::Prefill,
/*is_zellij*/ false,
),
InsertHistoryMode::FullScreenReplayPrefill
);
}
#[test]
fn unfocused_notification_condition_emits_when_unfocused() {
assert!(should_emit_notification(
@@ -321,32 +266,6 @@ mod tests {
/*linux_term_program*/ None, /*windows_term_program*/ None
));
}
#[test]
fn resize_reflow_replay_invalidates_without_clearing_after_insert() {
assert_eq!(
resize_reflow_draw_refresh(
/*needs_full_repaint*/ true, /*flushed_reflow_history*/ true
),
ResizeReflowDrawRefresh {
clear_after_history_flush: false,
invalidate_viewport: true,
}
);
}
#[test]
fn resize_reflow_draw_refresh_preserves_legacy_clear_without_replay() {
assert_eq!(
resize_reflow_draw_refresh(
/*needs_full_repaint*/ true, /*flushed_reflow_history*/ false
),
ResizeReflowDrawRefresh {
clear_after_history_flush: true,
invalidate_viewport: true,
}
);
}
}
pub fn set_modes() -> Result<()> {
@@ -544,9 +463,6 @@ pub struct Tui {
event_broker: Arc<EventBroker>,
pub(crate) terminal: Terminal,
pending_history_lines: Vec<Line<'static>>,
// Reflowed transcript rows are written through a separate queue so the feature-on draw path can
// preserve the inline viewport while the legacy queue keeps its pre-feature insertion behavior.
pending_reflow_history_lines: Vec<Line<'static>>,
alt_saved_viewport: Option<ratatui::layout::Rect>,
#[cfg(unix)]
suspend_context: SuspendContext,
@@ -562,24 +478,6 @@ pub struct Tui {
alt_screen_enabled: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct ResizeReflowDrawRefresh {
clear_after_history_flush: bool,
invalidate_viewport: bool,
}
fn resize_reflow_draw_refresh(
needs_full_repaint: bool,
flushed_reflow_history: bool,
) -> ResizeReflowDrawRefresh {
ResizeReflowDrawRefresh {
// Resize reflow clears the terminal before queueing rebuilt rows. Clearing again after
// replay can erase the source-backed tail rows that were just inserted.
clear_after_history_flush: needs_full_repaint && !flushed_reflow_history,
invalidate_viewport: needs_full_repaint,
}
}
impl Tui {
pub fn new(terminal: Terminal) -> Self {
let (draw_tx, _) = broadcast::channel(1);
@@ -603,7 +501,6 @@ impl Tui {
event_broker: Arc::new(EventBroker::new()),
terminal,
pending_history_lines: vec![],
pending_reflow_history_lines: vec![],
alt_saved_viewport: None,
#[cfg(unix)]
suspend_context: SuspendContext::new(),
@@ -782,14 +679,8 @@ impl Tui {
self.frame_requester().schedule_frame();
}
pub(crate) fn insert_reflowed_history_lines(&mut self, lines: Vec<Line<'static>>) {
self.pending_reflow_history_lines.extend(lines);
self.frame_requester().schedule_frame();
}
pub fn clear_pending_history_lines(&mut self) {
self.pending_history_lines.clear();
self.pending_reflow_history_lines.clear();
}
/// Resize the inline viewport to `height` rows, scrolling content above it if
@@ -916,31 +807,6 @@ impl Tui {
Ok(is_zellij)
}
/// Write reflowed transcript rows with the configured resize-replay strategy.
///
/// These rows come from a source-backed rebuild after Codex has already decided which
/// transcript cells should be visible at the new width. Standard replay uses the same
/// viewport-aware insertion path as startup replay; full-screen replay modes keep their
/// experimental terminal-specific behavior isolated behind the config knob.
fn flush_pending_reflow_history_lines(
terminal: &mut Terminal,
pending_reflow_history_lines: &mut Vec<Line<'static>>,
replay_mode: TerminalResizeReflowReplayMode,
is_zellij: bool,
) -> Result<bool> {
if pending_reflow_history_lines.is_empty() {
return Ok(false);
}
crate::insert_history::insert_history_lines_with_mode(
terminal,
pending_reflow_history_lines.clone(),
insert_history_mode_for_resize_reflow(replay_mode, is_zellij),
)?;
pending_reflow_history_lines.clear();
Ok(true)
}
pub fn draw(
&mut self,
height: u16,
@@ -1009,7 +875,6 @@ impl Tui {
pub fn draw_with_resize_reflow(
&mut self,
height: u16,
replay_mode: TerminalResizeReflowReplayMode,
draw_fn: impl FnOnce(&mut custom_terminal::Frame),
) -> Result<()> {
// If we are resuming from ^Z, we need to prepare the resume action now so we can apply it
@@ -1034,19 +899,8 @@ impl Tui {
self.is_zellij,
)?;
needs_full_repaint |= flushed_history;
let flushed_reflow_history = Self::flush_pending_reflow_history_lines(
terminal,
&mut self.pending_reflow_history_lines,
replay_mode,
self.is_zellij,
)?;
needs_full_repaint |= flushed_reflow_history;
let refresh = resize_reflow_draw_refresh(needs_full_repaint, flushed_reflow_history);
if refresh.clear_after_history_flush {
terminal.clear()?;
}
if refresh.invalidate_viewport {
if needs_full_repaint {
terminal.invalidate_viewport();
}