mirror of
https://github.com/openai/codex.git
synced 2026-05-04 11:26:33 +00:00
fix: add tui.alternate_screen config and --no-alt-screen CLI flag for Zellij scrollback (#8555)
Fixes #2558 Codex uses alternate screen mode (CSI 1049) which, per xterm spec, doesn't support scrollback. Zellij follows this strictly, so users can't scroll back through output. **Changes:** - Add `tui.alternate_screen` config: `auto` (default), `always`, `never` - Add `--no-alt-screen` CLI flag - Auto-detect Zellij and skip alt screen (uses existing `ZELLIJ` env var detection) **Usage:** ```bash # CLI flag codex --no-alt-screen # Or in config.toml [tui] alternate_screen = "never" ``` With default `auto` mode, Zellij users get working scrollback without any config changes. --------- Co-authored-by: Josh McKinney <joshka@openai.com>
This commit is contained in:
@@ -22,6 +22,8 @@ use codex_core::config::resolve_oss_provider;
|
||||
use codex_core::find_thread_path_by_id_str;
|
||||
use codex_core::get_platform_sandbox;
|
||||
use codex_core::protocol::AskForApproval;
|
||||
use codex_core::terminal::Multiplexer;
|
||||
use codex_protocol::config_types::AltScreenMode;
|
||||
use codex_protocol::config_types::SandboxMode;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use std::fs::OpenOptions;
|
||||
@@ -515,12 +517,39 @@ async fn run_ratatui_app(
|
||||
resume_picker::ResumeSelection::StartFresh
|
||||
};
|
||||
|
||||
let Cli { prompt, images, .. } = cli;
|
||||
let Cli {
|
||||
prompt,
|
||||
images,
|
||||
no_alt_screen,
|
||||
..
|
||||
} = cli;
|
||||
|
||||
// Run the main chat + transcript UI on the terminal's alternate screen so
|
||||
// the entire viewport can be used without polluting normal scrollback. This
|
||||
// mirrors the behavior of the legacy TUI but keeps inline mode available
|
||||
// for smaller prompts like onboarding and model migration.
|
||||
//
|
||||
// However, alternate screen prevents scrollback in terminal multiplexers like
|
||||
// Zellij that strictly follow the xterm spec (which disallows scrollback in
|
||||
// alternate screen buffers). This auto-detects the terminal and disables
|
||||
// alternate screen in Zellij while keeping it enabled elsewhere.
|
||||
let use_alt_screen = if no_alt_screen {
|
||||
// CLI flag explicitly disables alternate screen
|
||||
false
|
||||
} else {
|
||||
match config.tui_alternate_screen {
|
||||
AltScreenMode::Always => true,
|
||||
AltScreenMode::Never => false,
|
||||
AltScreenMode::Auto => {
|
||||
// Auto-detect: disable in Zellij, enable elsewhere
|
||||
let terminal_info = codex_core::terminal::terminal_info();
|
||||
!matches!(terminal_info.multiplexer, Some(Multiplexer::Zellij { .. }))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Set flag on Tui so all enter_alt_screen() calls respect the setting
|
||||
tui.set_alt_screen_enabled(use_alt_screen);
|
||||
let _ = tui.enter_alt_screen();
|
||||
|
||||
let app_result = App::run(
|
||||
|
||||
Reference in New Issue
Block a user