Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Add `/tui` to choose the terminal UI mode for the next launch (#46883)

Felipe Coury2f34d236f533
diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs
index b8ccea3daf..182d5fb60d 100644
--- a/codex-rs/tui/src/app.rs
+++ b/codex-rs/tui/src/app.rs
@@ -265,6 +265,7 @@ mod thread_session_state;
mod thread_settings;
mod thread_title;
mod transcript_export;
+mod tui_mode_picker;
mod user_verification;
mod user_verification_errors;
mod user_verification_requests;
diff --git a/codex-rs/tui/src/app/event_dispatch.rs b/codex-rs/tui/src/app/event_dispatch.rs
index ae96c47197..ad2aa6b557 100644
--- a/codex-rs/tui/src/app/event_dispatch.rs
+++ b/codex-rs/tui/src/app/event_dispatch.rs
@@ -2871,6 +2871,9 @@ impl App {
));
}
},
+ AppEvent::FullscreenTranscriptSelected { enabled } => {
+ self.save_fullscreen_transcript(enabled).await;
+ }
AppEvent::StatusLineSetup {
items,
use_theme_colors,
diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__tui_mode_picker__tests__tui_mode_picker_requires_confirmation_and_explains_restart.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__tui_mode_picker__tests__tui_mode_picker_requires_confirmation_and_explains_restart.snap
new file mode 100644
index 0000000000..1182bbdff3
--- /dev/null
+++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__tui_mode_picker__tests__tui_mode_picker_requires_confirmation_and_explains_restart.snap
@@ -0,0 +1,55 @@
+---
+source: tui/src/app/tui_mode_picker_tests.rs
+expression: "screens.join(\"\\n\\n\")"
+---
+fullscreen=false, width=80
+ TUI mode for next launch
+
+
+› 1. Scrollback (current) Use your terminal's scrollback
+ 2. Fullscreen Scroll within Codex's fullscreen view
+
+ Restart to apply. Launch overrides still apply.
+ enter select · esc back
+
+fullscreen=false, width=40
+ TUI mode for next launch
+
+
+› 1. Scrollback (current) Use your
+ terminal's
+ scrollback
+ 2. Fullscreen Scroll within
+ Codex's
+ fullscreen
+ view
+
+ Restart to apply. Launch overrides
+ still apply.
+ enter select · esc back
+
+fullscreen=true, width=80
+ TUI mode for next launch
+
+
+ 1. Scrollback Use your terminal's scrollback
+› 2. Fullscreen (current) Scroll within Codex's fullscreen view
+
+ Restart to apply. Launch overrides still apply.
+ enter select · esc back
+
+fullscreen=true, width=40
+ TUI mode for next launch
+
+
+ 1. Scrollback Use your
+ terminal's
+ scrollback
+› 2. Fullscreen (current) Scroll within
+ Codex's
+ fullscreen
+ view
+
+ Restart to apply. Launch overrides
+ still apply.
+ enter select · esc back
diff --git a/codex-rs/tui/src/app/tui_mode_picker.rs b/codex-rs/tui/src/app/tui_mode_picker.rs
new file mode 100644
index 0000000000..6a2341e8ad
--- /dev/null
+++ b/codex-rs/tui/src/app/tui_mode_picker.rs
@@ -0,0 +1,38 @@
+//! Persist the next launch's renderer preference without touching terminal ownership.
+
+use super::App;
+use crate::config_update::format_config_error;
+use crate::legacy_core::config::edit::ConfigEdit;
+use crate::legacy_core::config::edit::ConfigEditsBuilder;
+
+impl App {
+ pub(super) async fn save_fullscreen_transcript(&mut self, enabled: bool) {
+ let result =
+ ConfigEditsBuilder::for_config_path(self.local_settings.user_config_path.as_path())
+ .with_edits([ConfigEdit::SetPath {
+ segments: vec!["tui".into(), "fullscreen_transcript".into()],
+ value: toml_edit::value(enabled),
+ }])
+ .apply()
+ .await;
+ match result {
+ Ok(()) => {
+ self.local_settings.tui.fullscreen_transcript = enabled;
+ self.chat_widget.local_settings.tui.fullscreen_transcript = enabled;
+ let mode = if enabled { "Fullscreen" } else { "Scrollback" };
+ self.chat_widget.add_info_message(
+ format!("Saved TUI mode: {mode}. Restart Codex to apply; launch overrides still apply."),
+ /*hint*/ None,
+ );
+ }
+ Err(error) => self.chat_widget.add_error_message(format!(
+ "Failed to save TUI mode: {}",
+ format_config_error(&error),
+ )),
+ }
+ }
+}
+
+#[cfg(test)]
+#[path = "tui_mode_picker_tests.rs"]
+mod tests;
diff --git a/codex-rs/tui/src/app/tui_mode_picker_tests.rs b/codex-rs/tui/src/app/tui_mode_picker_tests.rs
new file mode 100644
index 0000000000..3bf1eaf27b
--- /dev/null
+++ b/codex-rs/tui/src/app/tui_mode_picker_tests.rs
@@ -0,0 +1,121 @@
+//! Picker confirmation and selected-file persistence leave the running renderer unchanged.
+
+use crate::app::tests::make_test_app_with_channels;
+use crate::app_event::AppEvent;
+use crate::chatwidget::tests::helpers::render_bottom_popup;
+use crate::legacy_core::config::ConfigBuilder;
+use codex_config::LoaderOverrides;
+use codex_utils_absolute_path::AbsolutePathBuf;
+use crossterm::event::KeyCode;
+use pretty_assertions::assert_eq;
+
+#[tokio::test]
+async fn tui_mode_picker_requires_confirmation_and_explains_restart() {
+ let mut screens = Vec::new();
+ for current in [false, true] {
+ let (mut app, mut events, _ops) = make_test_app_with_channels().await;
+ app.chat_widget.local_settings.tui.fullscreen_transcript = current;
+ let before = app.chat_widget.local_settings.clone();
+ let other = if current { KeyCode::Up } else { KeyCode::Down };
+ app.chat_widget.show_tui_mode_picker();
+ for width in [80, 40] {
+ screens.push(format!(
+ "fullscreen={current}, width={width}\n{}",
+ render_bottom_popup(&app.chat_widget, width)
+ ));
+ }
+ app.chat_widget.handle_key_event(other.into());
+ app.chat_widget.handle_key_event(KeyCode::Esc.into());
+ assert_eq!(app.chat_widget.local_settings, before);
+ while let Ok(event) = events.try_recv() {
+ assert!(!matches!(
+ event,
+ AppEvent::FullscreenTranscriptSelected { .. }
+ ));
+ }
+ app.chat_widget.show_tui_mode_picker();
+ app.chat_widget.handle_key_event(other.into());
+ app.chat_widget.handle_key_event(KeyCode::Enter.into());
+ let mut choices = Vec::new();
+ while let Ok(event) = events.try_recv() {
+ if let AppEvent::FullscreenTranscriptSelected { enabled } = event {
+ choices.push(enabled);
+ }
+ }
+ assert_eq!(choices, vec![!current]);
+ assert_eq!(app.chat_widget.local_settings, before);
+ }
+ insta::assert_snapshot!(screens.join("\n\n"));
+}
+
+#[tokio::test]
+async fn tui_mode_picker_saves_selected_config_without_changing_the_live_mode() -> anyhow::Result<()>
+{
+ let home = tempfile::tempdir()?;
+ let base = home.path().join("config.toml");
+ let selected = AbsolutePathBuf::from_absolute_path(home.path().join("work.config.toml"))?;
+ std::fs::write(&base, "# untouched base config\n")?;
+ std::fs::write(&selected, "[tui]\nanimations = false\n")?;
+ let (mut app, _events, _ops) = make_test_app_with_channels().await;
+ app.local_settings.user_config_path = selected.clone();
+ let mut expected_app = app.local_settings.clone();
+ let mut expected_widget = app.chat_widget.local_settings.clone();
+ for enabled in [true, false] {
+ app.save_fullscreen_transcript(enabled).await;
+ expected_app.tui.fullscreen_transcript = enabled;
+ expected_widget.tui.fullscreen_transcript = enabled;
+ assert_eq!(
+ (&app.local_settings, &app.chat_widget.local_settings),
+ (&expected_app, &expected_widget)
+ );
+ let saved: toml::Value = toml::from_str(&std::fs::read_to_string(&selected)?)?;
+ assert_eq!(
+ serde_json::to_value(saved)?,
+ serde_json::json!({"tui": {"animations": false, "fullscreen_transcript": enabled}})
+ );
+ let reloaded = ConfigBuilder::default()
+ .codex_home(home.path().to_path_buf())
+ .loader_overrides(LoaderOverrides {
+ user_config_path: Some(selected.clone()),
+ ignore_project_config: true,
+ ..LoaderOverrides::without_managed_config_for_tests()
+ })
+ .build()
+ .await?;
+ assert_eq!(reloaded.tui_fullscreen_transcript, enabled);
+ }
+ assert_eq!(std::fs::read_to_string(base)?, "# untouched base config\n");
+ Ok(())
+}
+
+#[tokio::test]
+async fn tui_mode_picker_failed_save_preserves_the_preference() -> anyhow::Result<()> {
+ let home = tempfile::tempdir()?;
+ let path = home.path().join("config.toml");
+ std::fs::write(&path, "[invalid\n")?;
+ let (mut app, mut events, _ops) = make_test_app_with_channels().await;
+ app.local_settings.user_config_path = AbsolutePathBuf::from_absolute_path(&path)?;
+ let before = (
+ app.local_settings.clone(),
+ app.chat_widget.local_settings.clone(),
+ );
+ app.save_fullscreen_transcript(!before.0.tui.fullscreen_transcript)
+ .await;
+ assert_eq!(
+ (&app.local_settings, &app.chat_widget.local_settings),
+ (&before.0, &before.1)
+ );
+ assert_eq!(std::fs::read_to_string(path)?, "[invalid\n");
+ let mut messages = Vec::new();
+ while let Ok(event) = events.try_recv() {
+ if let AppEvent::InsertHistoryCell(cell) = event {
+ messages.extend(
+ cell.display_lines(/*width*/ 80)
+ .iter()
+ .map(ToString::to_string),
+ );
+ }
+ }
+ assert!(messages.join("\n").contains("Failed to save TUI mode"));
+ Ok(())
+}
diff --git a/codex-rs/tui/src/app_event.rs b/codex-rs/tui/src/app_event.rs
index 71e5206777..b78150b379 100644
--- a/codex-rs/tui/src/app_event.rs
+++ b/codex-rs/tui/src/app_event.rs
@@ -1493,6 +1493,11 @@ pub(crate) enum AppEvent {
/// Dismiss the terminal-title setup UI without changing config.
TerminalTitleSetupCancelled,
+ /// Save the transcript renderer preference for the next launch only.
+ FullscreenTranscriptSelected {
+ enabled: bool,
+ },
+
/// Apply a user-confirmed syntax theme selection.
SyntaxThemeSelected {
name: String,
diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__command_popup__tests__command_popup_default_items.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__command_popup__tests__command_popup_default_items.snap
index 02817d96bb..3e04054c91 100644
--- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__command_popup__tests__command_popup_default_items.snap
+++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__command_popup__tests__command_popup_default_items.snap
@@ -29,6 +29,7 @@ expression: commands
/copy - copy the last response or part of it
/export - export the conversation as markdown
/raw - toggle raw scrollback mode for copy-friendly terminal selection
+/tui - choose the TUI mode for the next launch
/diff - show git diff (including untracked files)
/mention - mention a file
/status - show current session configuration and token usage
diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs
index d30ad2c730..db29601868 100644
--- a/codex-rs/tui/src/chatwidget.rs
+++ b/codex-rs/tui/src/chatwidget.rs
@@ -451,6 +451,7 @@ mod tool_lifecycle;
mod tool_requests;
mod transcript;
mod transcript_export;
+mod tui_mode_picker;
mod usage_history;
use self::transcript::TranscriptState;
mod turn_lifecycle;
diff --git a/codex-rs/tui/src/chatwidget/slash_dispatch.rs b/codex-rs/tui/src/chatwidget/slash_dispatch.rs
index d96474c2da..50081a03fd 100644
--- a/codex-rs/tui/src/chatwidget/slash_dispatch.rs
+++ b/codex-rs/tui/src/chatwidget/slash_dispatch.rs
@@ -461,6 +461,7 @@ impl ChatWidget {
let enabled = self.toggle_raw_output_mode_and_notify();
self.emit_raw_output_mode_changed(enabled);
}
+ SlashCommand::Tui => self.show_tui_mode_picker(),
SlashCommand::Diff => {
self.add_diff_in_progress();
let tx = self.app_event_tx.clone();
@@ -1267,6 +1268,7 @@ impl ChatWidget {
| SlashCommand::Title
| SlashCommand::Statusline
| SlashCommand::Theme
+ | SlashCommand::Tui
| SlashCommand::Pets => QueueDrain::Stop,
}
}
diff --git a/codex-rs/tui/src/chatwidget/tui_mode_picker.rs b/codex-rs/tui/src/chatwidget/tui_mode_picker.rs
new file mode 100644
index 0000000000..ce52b0a424
--- /dev/null
+++ b/codex-rs/tui/src/chatwidget/tui_mode_picker.rs
@@ -0,0 +1,38 @@
+//! Choose the next launch's transcript renderer without changing this session.
+
+use super::ChatWidget;
+use crate::app_event::AppEvent;
+use crate::bottom_pane::SelectionDescriptionLayout;
+use crate::bottom_pane::SelectionItem;
+use crate::bottom_pane::SelectionViewParams;
+use crate::bottom_pane::popup_consts::picker_hint_line_for_keymap;
+
+impl ChatWidget {
+ pub(crate) fn show_tui_mode_picker(&mut self) {
+ let items = [
+ (false, "Scrollback", "Use your terminal's scrollback"),
+ (true, "Fullscreen", "Scroll within Codex's fullscreen view"),
+ ]
+ .into_iter()
+ .map(|(enabled, name, description)| SelectionItem {
+ name: name.into(),
+ description: Some(description.into()),
+ is_current: enabled == self.local_settings.tui.fullscreen_transcript,
+ actions: vec![Box::new(move |tx| {
+ tx.send(AppEvent::FullscreenTranscriptSelected { enabled });
+ })],
+ dismiss_on_select: true,
+ require_explicit_confirmation: true,
+ ..Default::default()
+ })
+ .collect();
+ self.show_selection_view(SelectionViewParams {
+ title: Some("TUI mode for next launch".into()),
+ description_layout: SelectionDescriptionLayout::Columns,
+ footer_note: Some("Restart to apply. Launch overrides still apply.".into()),
+ footer_hint: Some(picker_hint_line_for_keymap(&self.bottom_pane.list_keymap())),
+ items,
+ ..SelectionViewParams::picker()
+ });
+ }
+}
diff --git a/codex-rs/tui/src/slash_command.rs b/codex-rs/tui/src/slash_command.rs
index 981aa5be9d..160d0407ec 100644
--- a/codex-rs/tui/src/slash_command.rs
+++ b/codex-rs/tui/src/slash_command.rs
@@ -47,6 +47,7 @@ pub enum SlashCommand {
Copy,
Export,
Raw,
+ Tui,
Diff,
Mention,
Status,
@@ -106,6 +107,7 @@ impl SlashCommand {
SlashCommand::Copy => "copy the last response or part of it",
SlashCommand::Export => "export the conversation as markdown",
SlashCommand::Raw => "toggle raw scrollback mode for copy-friendly terminal selection",
+ SlashCommand::Tui => "choose the TUI mode for the next launch",
SlashCommand::Diff => "show git diff (including untracked files)",
SlashCommand::Mention => "mention a file",
SlashCommand::Skills => "use skills to improve how Codex performs specific tasks",
@@ -246,6 +248,7 @@ impl SlashCommand {
| SlashCommand::Recap
| SlashCommand::Export
| SlashCommand::Keymap
+ | SlashCommand::Tui
| SlashCommand::Vim
| SlashCommand::ElevateSandbox
| SlashCommand::Experimental
diff --git a/codex-rs/tui/tests/suite/focus_palette.rs b/codex-rs/tui/tests/suite/focus_palette.rs
index d13af5ad7b..038237da36 100644
--- a/codex-rs/tui/tests/suite/focus_palette.rs
+++ b/codex-rs/tui/tests/suite/focus_palette.rs
@@ -22,6 +22,9 @@ const STARTUP_TIMEOUT: Duration = Duration::from_secs(/*secs*/ 30);
const FOCUS_INPUT_TIMEOUT: Duration = Duration::from_secs(/*secs*/ 5);
const FOCUS_PROBE_INPUT: &str = "focus-palette-24527";
+#[path = "tui_mode_picker_tests.rs"]
+mod tui_mode_picker;
+
#[test]
fn focus_gained_with_unanswered_palette_queries_preserves_immediate_input() -> Result<()> {
let repo_root = codex_utils_cargo_bin::repo_root()?;
diff --git a/codex-rs/tui/tests/suite/tui_mode_picker_tests.rs b/codex-rs/tui/tests/suite/tui_mode_picker_tests.rs
new file mode 100644
index 0000000000..88945a613d
--- /dev/null
+++ b/codex-rs/tui/tests/suite/tui_mode_picker_tests.rs
@@ -0,0 +1,66 @@
+//! The picker persists a preference, but only a new process adopts the renderer.
+
+use super::*;
+use pretty_assertions::assert_eq;
+
+#[test]
+fn tui_mode_picker_applies_only_after_restart() -> Result<()> {
+ let root = codex_utils_cargo_bin::repo_root()?;
+ let mut home = tempfile::tempdir()?;
+ write_test_config(home.path(), &root)?;
+ let path = home.path().join("config.toml");
+ let config = std::fs::read_to_string(&path)?;
+ std::fs::write(
+ &path,
+ format!(
+ "tui.fullscreen_transcript = false\ntui.alternate_screen = \"always\"\ntui.disable_paste_burst = true\ntui.status_line = [\"thread-id\"]\n{config}"
+ ),
+ )?;
+ for (launch, current) in [false, true, false].into_iter().enumerate() {
+ let mut terminal = PtyCodex::start(&root, home, &[])?;
+ terminal.wait_for_startup()?;
+ // The header precedes session setup; wait for the thread ID before sending commands.
+ let deadline = Instant::now() + STARTUP_TIMEOUT;
+ loop {
+ terminal.read_output(Duration::from_millis(/*millis*/ 50))?;
+ terminal.answer_startup_queries()?;
+ if terminal
+ .screen_contents()
+ .split_whitespace()
+ .any(|word| uuid::Uuid::parse_str(word).is_ok())
+ {
+ break;
+ }
+ ensure!(
+ Instant::now() < deadline,
+ "thread did not become ready: {}",
+ terminal.screen_contents()
+ );
+ terminal.ensure_running()?;
+ }
+ assert_eq!(terminal.parser.screen().alternate_screen(), current);
+ if launch == 2 {
+ break;
+ }
+ terminal.write_input(b"/tui")?;
+ terminal.wait_for_screen("/tui")?;
+ terminal.write_input(b"\r")?;
+ terminal.wait_for_screen("TUI mode for next launch")?;
+ terminal.write_input(if current { b"\x1b[A" } else { b"\x1b[B" })?;
+ terminal.write_input(b"\r")?;
+ terminal.wait_for_screen(if current {
+ "Saved TUI mode: Scrollback"
+ } else {
+ "Saved TUI mode: Fullscreen"
+ })?;
+ assert_eq!(terminal.parser.screen().alternate_screen(), current);
+ let saved: toml::Value = toml::from_str(&std::fs::read_to_string(&path)?)?;
+ assert_eq!(
+ saved["tui"]["fullscreen_transcript"].as_bool(),
+ Some(!current)
+ );
+ home = std::mem::replace(&mut terminal._codex_home, tempfile::tempdir()?);
+ drop(terminal);
+ }
+ Ok(())
+}