mirror of
https://github.com/openai/codex.git
synced 2026-12-01 00:20:48 +00:00
wip(tui): toggle resize reflow replay mode
This commit is contained in:
@@ -534,6 +534,17 @@ 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 using transcript rows directly, without extra blank prefill rows.
|
||||
#[default]
|
||||
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)]
|
||||
@@ -544,6 +555,10 @@ 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.
|
||||
|
||||
@@ -1933,6 +1933,25 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"TerminalResizeReflowReplayModeToml": {
|
||||
"description": "How resize reflow should rebuild terminal scrollback during this experimental phase.",
|
||||
"oneOf": [
|
||||
{
|
||||
"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.",
|
||||
@@ -1943,6 +1962,15 @@
|
||||
"format": "uint",
|
||||
"minimum": 0.0,
|
||||
"type": "integer"
|
||||
},
|
||||
"replay_mode": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/TerminalResizeReflowReplayModeToml"
|
||||
}
|
||||
],
|
||||
"default": "direct",
|
||||
"description": "Temporary testing knob for selecting the terminal scrollback replay strategy."
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
@@ -2084,7 +2112,8 @@
|
||||
}
|
||||
],
|
||||
"default": {
|
||||
"max_rows": null
|
||||
"max_rows": null,
|
||||
"replay_mode": "direct"
|
||||
},
|
||||
"description": "Experimental terminal resize-reflow tuning knobs."
|
||||
},
|
||||
|
||||
@@ -43,6 +43,7 @@ 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;
|
||||
@@ -518,10 +519,42 @@ max_rows = 9000
|
||||
.terminal_resize_reflow,
|
||||
TerminalResizeReflowToml {
|
||||
max_rows: Some(9000),
|
||||
replay_mode: TerminalResizeReflowReplayModeToml::Direct,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_toml_deserializes_terminal_resize_reflow_replay_mode() {
|
||||
let cfg: ConfigToml = toml::from_str(
|
||||
r#"
|
||||
[tui.terminal_resize_reflow]
|
||||
replay_mode = "prefill"
|
||||
"#,
|
||||
)
|
||||
.expect("TOML deserialization should succeed for resize reflow replay mode");
|
||||
|
||||
assert_eq!(
|
||||
cfg.tui
|
||||
.expect("tui config should deserialize")
|
||||
.terminal_resize_reflow
|
||||
.replay_mode,
|
||||
TerminalResizeReflowReplayModeToml::Prefill
|
||||
);
|
||||
}
|
||||
|
||||
#[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(
|
||||
@@ -1339,12 +1372,17 @@ 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::Direct
|
||||
);
|
||||
|
||||
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()
|
||||
}),
|
||||
@@ -1364,7 +1402,10 @@ 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) },
|
||||
terminal_resize_reflow: TerminalResizeReflowToml {
|
||||
max_rows: Some(0),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
@@ -1379,6 +1420,28 @@ 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]
|
||||
|
||||
@@ -636,9 +636,17 @@ pub enum TerminalResizeReflowMaxRows {
|
||||
Limit(usize),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum TerminalResizeReflowReplayMode {
|
||||
#[default]
|
||||
Direct,
|
||||
Prefill,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub struct TerminalResizeReflowConfig {
|
||||
pub max_rows: TerminalResizeReflowMaxRows,
|
||||
pub replay_mode: TerminalResizeReflowReplayMode,
|
||||
}
|
||||
|
||||
impl AuthManagerConfig for Config {
|
||||
@@ -1509,6 +1517,14 @@ 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::Direct => {
|
||||
TerminalResizeReflowReplayMode::Direct
|
||||
}
|
||||
codex_config::types::TerminalResizeReflowReplayModeToml::Prefill => {
|
||||
TerminalResizeReflowReplayMode::Prefill
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-6
@@ -1159,12 +1159,16 @@ 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, |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,
|
||||
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));
|
||||
}
|
||||
},
|
||||
)?;
|
||||
} else {
|
||||
tui.draw(desired_height, |frame| {
|
||||
self.chat_widget.render(frame.area(), frame.buffer);
|
||||
|
||||
@@ -671,6 +671,7 @@ mod tests {
|
||||
r#"
|
||||
[tui.terminal_resize_reflow]
|
||||
max_rows = 9000
|
||||
replay_mode = "prefill"
|
||||
"#,
|
||||
)?;
|
||||
|
||||
@@ -680,6 +681,10 @@ max_rows = 9000
|
||||
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(())
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,6 @@ pub enum InsertHistoryMode {
|
||||
Standard,
|
||||
Zellij,
|
||||
FullScreenReplayPrefill,
|
||||
// Kept available while validating terminal-specific replay behavior.
|
||||
#[allow(dead_code)]
|
||||
FullScreenReplayDirect,
|
||||
}
|
||||
|
||||
@@ -950,4 +948,32 @@ mod tests {
|
||||
);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ mod tests {
|
||||
let terminal = test_terminal(TerminalName::VsCode);
|
||||
let config = TerminalResizeReflowConfig {
|
||||
max_rows: TerminalResizeReflowMaxRows::Limit(42),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
@@ -143,6 +144,7 @@ mod tests {
|
||||
let terminal = test_terminal(TerminalName::VsCode);
|
||||
let config = TerminalResizeReflowConfig {
|
||||
max_rows: TerminalResizeReflowMaxRows::Disabled,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
|
||||
+33
-1
@@ -41,6 +41,7 @@ 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;
|
||||
@@ -173,14 +174,30 @@ fn should_emit_notification(condition: NotificationCondition, terminal_focused:
|
||||
}
|
||||
}
|
||||
|
||||
fn insert_history_mode_for_resize_reflow(
|
||||
replay_mode: TerminalResizeReflowReplayMode,
|
||||
) -> crate::insert_history::InsertHistoryMode {
|
||||
match replay_mode {
|
||||
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]
|
||||
@@ -199,6 +216,18 @@ mod tests {
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resize_reflow_replay_mode_selects_insert_history_mode() {
|
||||
assert_eq!(
|
||||
insert_history_mode_for_resize_reflow(TerminalResizeReflowReplayMode::Direct),
|
||||
InsertHistoryMode::FullScreenReplayDirect
|
||||
);
|
||||
assert_eq!(
|
||||
insert_history_mode_for_resize_reflow(TerminalResizeReflowReplayMode::Prefill),
|
||||
InsertHistoryMode::FullScreenReplayPrefill
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unfocused_notification_condition_emits_when_unfocused() {
|
||||
assert!(should_emit_notification(
|
||||
@@ -871,6 +900,7 @@ impl Tui {
|
||||
fn flush_pending_reflow_history_lines(
|
||||
terminal: &mut Terminal,
|
||||
pending_reflow_history_lines: &mut Vec<Line<'static>>,
|
||||
replay_mode: TerminalResizeReflowReplayMode,
|
||||
) -> Result<bool> {
|
||||
if pending_reflow_history_lines.is_empty() {
|
||||
return Ok(false);
|
||||
@@ -879,7 +909,7 @@ impl Tui {
|
||||
crate::insert_history::insert_history_lines_with_mode(
|
||||
terminal,
|
||||
pending_reflow_history_lines.clone(),
|
||||
crate::insert_history::InsertHistoryMode::FullScreenReplayPrefill,
|
||||
insert_history_mode_for_resize_reflow(replay_mode),
|
||||
)?;
|
||||
pending_reflow_history_lines.clear();
|
||||
Ok(true)
|
||||
@@ -953,6 +983,7 @@ 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
|
||||
@@ -980,6 +1011,7 @@ impl Tui {
|
||||
let flushed_reflow_history = Self::flush_pending_reflow_history_lines(
|
||||
terminal,
|
||||
&mut self.pending_reflow_history_lines,
|
||||
replay_mode,
|
||||
)?;
|
||||
needs_full_repaint |= flushed_reflow_history;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user