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

## What changed

Add a picker for Scrollback and Fullscreen modes that requires explicit
confirmation and saves `tui.fullscreen_transcript` to the selected user config
file. Keep the running renderer unchanged and explain that a restart is required
and launch overrides still apply. Report save failures without changing the
stored preference in memory.

## Testing

Add picker snapshots and tests for confirmation, cancellation, selected-config
persistence, and failed saves. Add a PTY test covering mode changes in both
directions across restarts while verifying that the current session stays in
its original mode.

GitOrigin-RevId: 7f231ab37c89e2168133fcfd6aaee54775aa7972
This commit is contained in:
Felipe Coury
2026-09-20 20:38:26 +00:00
committed by copyberry
parent 93b44c3a73
commit 2f34d236f5
13 changed files with 337 additions and 0 deletions
+1
View File
@@ -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;
+3
View File
@@ -2871,6 +2871,9 @@ impl App {
));
}
},
AppEvent::FullscreenTranscriptSelected { enabled } => {
self.save_fullscreen_transcript(enabled).await;
}
AppEvent::StatusLineSetup {
items,
use_theme_colors,
@@ -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
+38
View File
@@ -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;
@@ -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(())
}
+5
View File
@@ -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,
@@ -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
+1
View File
@@ -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;
@@ -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,
}
}
@@ -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()
});
}
}
+3
View File
@@ -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
@@ -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()?;
@@ -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(())
}