feat(tui): remove Zellij TUI workarounds (#22214)

## Why

We added Zellij-specific TUI workarounds because older Zellij behavior
did not work with Codex's normal terminal model:

- #8555 made `tui.alternate_screen = "auto"` disable alternate screen in
Zellij so transcript history stayed available.
- #16578 avoided scroll-region operations in Zellij by emitting raw
newlines and using a separate composer styling path.

This PR removes both workarounds because the latest Zellij release
tested locally (`zellij 0.44.1`) works correctly with Codex's standard
TUI behavior: normal alternate-screen handling, redraw, and history
insertion.

## What Changed

- Removed the `InsertHistoryMode::Zellij` path and the Zellij-only
newline scrollback insertion behavior.
- Removed cached `is_zellij` state from the TUI and composer.
- Removed Zellij-specific composer styling, the helper snapshot, and the
`TerminalInfo::is_zellij()` convenience method that only served this
workaround.
- Changed `tui.alternate_screen = "auto"` to use alternate screen for
Zellij too; `--no-alt-screen` and `tui.alternate_screen = "never"` still
preserve the inline mode escape hatch.
- Updated the generated config schema description for
`tui.alternate_screen`.

## How to Test

Manual smoke path used with `zellij 0.44.1`:

1. Build and run this branch inside a Zellij `0.44.1` session with
default config.
2. Start Codex normally and produce enough assistant/tool output to
create scrollback.
3. Confirm the transcript remains readable, the composer renders
normally, and scrolling through terminal history works.
4. Resize the Zellij pane while output exists and confirm the TUI
redraws without duplicated, missing, or stale rows.
5. Compare with `--no-alt-screen` or `-c tui.alternate_screen=never` if
you want to verify the inline fallback still works.

Targeted tests:
- `just write-config-schema`
- `just fmt`
- `just fix -p codex-tui`
- `cargo test -p codex-terminal-detection`
- `cargo test -p codex-tui alternate_screen_auto_uses_alt_screen`

Attempted but did not complete locally:
- `cargo test -p codex-tui` built and ran the new test successfully,
then failed later on unrelated local failures in
`status_permissions_full_disk_managed_*` and a stack overflow in
`tests::fork_last_filters_latest_session_by_cwd_unless_show_all`.

## Documentation

No developers.openai.com Codex documentation update is needed for this
revert.
This commit is contained in:
Felipe Coury authored and GitHub committed 2026-05-13 12:11:15 -03:00
1 parent 68e045a631
commit 6f77b70ff3
12 files changed
+126 -474

No files matched your search

+6 -121
View File
@@ -415,7 +415,6 @@ pub(crate) struct ChatComposer {
audio_device_selection_enabled: bool,
windows_degraded_sandbox_active: bool,
side_conversation_active: bool,
is_zellij: bool,
status_line_value: Option<Line<'static>>,
status_line_hyperlink_url: Option<String>,
status_line_enabled: bool,
@@ -599,10 +598,6 @@ impl ChatComposer {
audio_device_selection_enabled: false,
windows_degraded_sandbox_active: false,
side_conversation_active: false,
is_zellij: matches!(
codex_terminal_detection::terminal_info().multiplexer,
Some(codex_terminal_detection::Multiplexer::Zellij {})
),
status_line_value: None,
status_line_hyperlink_url: None,
status_line_enabled: false,
@@ -4788,56 +4783,20 @@ impl ChatComposer {
}
}
}
self.render_textarea(
composer_rect,
remote_images_rect,
textarea_rect,
buf,
mask_char,
);
}
/// Paint the composer's text input area, prompt chevron, and placeholder text.
///
/// In Zellij sessions the textarea uses explicit `Color::Reset` foreground styling
/// to prevent the multiplexer's pane chrome from bleeding into cell styles, and
/// substitutes hardcoded colors for `.bold()` / `.dim()` modifiers that Zellij
/// renders inconsistently. The standard path is unchanged.
fn render_textarea(
&self,
composer_rect: Rect,
remote_images_rect: Rect,
textarea_rect: Rect,
buf: &mut Buffer,
mask_char: Option<char>,
) {
let is_zellij = self.is_zellij;
let style = user_message_style();
let textarea_style = style.fg(ratatui::style::Color::Reset);
Block::default().style(style).render_ref(composer_rect, buf);
if !remote_images_rect.is_empty() {
Paragraph::new(self.remote_images_lines(remote_images_rect.width))
.style(style)
.render_ref(remote_images_rect, buf);
}
if is_zellij && !textarea_rect.is_empty() {
buf.set_style(textarea_rect, textarea_style);
}
if !textarea_rect.is_empty() {
let prompt = if self.input_enabled {
if self.is_bash_mode {
if is_zellij {
Span::from("!").light_red()
} else {
Span::from("!").light_red().bold()
}
} else if is_zellij {
Span::styled("›", style.fg(ratatui::style::Color::Cyan))
Span::from("!").light_red().bold()
} else {
"›".bold()
}
} else if is_zellij {
Span::styled("›", style.fg(ratatui::style::Color::DarkGray))
} else {
"›".dim()
};
@@ -4852,39 +4811,8 @@ impl ChatComposer {
let mut state = self.textarea_state.borrow_mut();
let textarea_is_empty = self.textarea.text().is_empty() && !self.is_bash_mode;
if let Some(mask_char) = mask_char {
self.textarea.render_ref_masked(
textarea_rect,
buf,
&mut state,
mask_char,
if is_zellij {
textarea_style
} else {
ratatui::style::Style::default()
},
);
} else if is_zellij && textarea_is_empty {
buf.set_style(textarea_rect, textarea_style);
} else if is_zellij {
let highlight_ranges = self.history_search_highlight_ranges();
if highlight_ranges.is_empty() {
self.textarea
.render_ref_styled(textarea_rect, buf, &mut state, textarea_style);
} else {
let highlight_style =
textarea_style.add_modifier(Modifier::REVERSED | Modifier::BOLD);
let highlights = highlight_ranges
.into_iter()
.map(|range| (range, highlight_style))
.collect::<Vec<_>>();
self.textarea.render_ref_styled_with_highlights(
textarea_rect,
buf,
&mut state,
textarea_style,
&highlights,
);
}
self.textarea
.render_ref_masked(textarea_rect, buf, &mut state, mask_char);
} else {
let highlight_ranges = self.history_search_highlight_ranges();
if highlight_ranges.is_empty() {
@@ -4915,18 +4843,9 @@ impl ChatComposer {
.to_string()
};
if !textarea_rect.is_empty() {
if is_zellij {
buf.set_string(
textarea_rect.x,
textarea_rect.y,
text,
textarea_style.fg(ratatui::style::Color::White).italic(),
);
} else {
let placeholder = Span::from(text).dim();
let line = Line::from(vec![placeholder]);
line.render_ref(textarea_rect.inner(Margin::new(0, 0)), buf);
}
let placeholder = Span::from(text).dim();
Line::from(vec![placeholder])
.render_ref(textarea_rect.inner(Margin::new(0, 0)), buf);
}
}
}
@@ -5149,35 +5068,6 @@ mod tests {
);
}
fn snapshot_zellij_composer_state<F>(name: &str, setup: F)
where
F: FnOnce(&mut ChatComposer),
{
use ratatui::Terminal;
use ratatui::backend::TestBackend;
let (tx, _rx) = unbounded_channel::<AppEvent>();
let sender = AppEventSender::new(tx);
let mut composer = ChatComposer::new(
/*has_input_focus*/ true,
sender,
/*enhanced_keys_supported*/ true,
"Ask Codex to do anything".to_string(),
/*disable_paste_burst*/ false,
);
composer.is_zellij = true;
setup(&mut composer);
let footer_props = composer.footer_props();
let footer_lines = footer_height(&footer_props);
let footer_spacing = ChatComposer::footer_spacing(footer_lines);
let height = footer_lines + footer_spacing + 8;
let mut terminal = Terminal::new(TestBackend::new(100, height)).unwrap();
terminal
.draw(|f| composer.render(f.area(), f.buffer_mut()))
.unwrap();
insta::assert_snapshot!(name, terminal.backend());
}
#[test]
fn footer_mode_snapshots() {
use crossterm::event::KeyCode;
@@ -5697,11 +5587,6 @@ mod tests {
);
}
#[test]
fn zellij_empty_composer_snapshot() {
snapshot_zellij_composer_state("zellij_empty_composer", |_composer| {});
}
#[test]
fn esc_hint_stays_hidden_with_draft_content() {
use crossterm::event::KeyCode;
@@ -1,14 +0,0 @@
---
source: tui/src/bottom_pane/chat_composer.rs
assertion_line: 4001
expression: terminal.backend()
---
" "
"› Ask Codex to do anything "
" "
" "
" "
" "
" "
" "
" ? for shortcuts 100% context left "
+4 -24
View File
@@ -24,6 +24,7 @@ use crossterm::event::KeyEventKind;
use crossterm::event::KeyModifiers;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Color;
use ratatui::style::Style;
use ratatui::widgets::StatefulWidgetRef;
use ratatui::widgets::WidgetRef;
@@ -1893,7 +1894,6 @@ impl TextArea {
buf: &mut Buffer,
state: &mut TextAreaState,
mask_char: char,
base_style: Style,
) {
let lines = self.wrapped_lines(area.width);
let scroll = self.effective_scroll(area.height, &lines, state.scroll);
@@ -1901,25 +1901,7 @@ impl TextArea {
let start = scroll as usize;
let end = (scroll + area.height).min(lines.len() as u16) as usize;
self.render_lines_masked(area, buf, &lines, start..end, mask_char, base_style);
}
/// Render the textarea with an explicit `base_style` applied to every cell,
/// used by the Zellij code path to override inherited terminal styles.
pub(crate) fn render_ref_styled(
&self,
area: Rect,
buf: &mut Buffer,
state: &mut TextAreaState,
base_style: Style,
) {
let lines = self.wrapped_lines(area.width);
let scroll = self.effective_scroll(area.height, &lines, state.scroll);
state.scroll = scroll;
let start = scroll as usize;
let end = (scroll + area.height).min(lines.len() as u16) as usize;
self.render_lines(area, buf, &lines, start..end, base_style, &[]);
self.render_lines_masked(area, buf, &lines, start..end, mask_char);
}
/// Render the textarea with `base_style` plus additional render-only highlight ranges.
@@ -1970,7 +1952,7 @@ impl TextArea {
}
let styled = &self.text[overlap_start..overlap_end];
let x_off = self.text[line_range.start..overlap_start].width() as u16;
let style = base_style.fg(ratatui::style::Color::Cyan);
let style = base_style.fg(Color::Cyan);
buf.set_string(area.x + x_off, y, styled, style);
}
@@ -1996,18 +1978,16 @@ impl TextArea {
lines: &[Range<usize>],
range: std::ops::Range<usize>,
mask_char: char,
base_style: Style,
) {
for (row, idx) in range.enumerate() {
let r = &lines[idx];
let y = area.y + row as u16;
let line_range = r.start..r.end - 1;
buf.set_style(Rect::new(area.x, y, area.width, 1), base_style);
let masked = self.text[line_range.clone()]
.chars()
.map(|_| mask_char)
.collect::<String>();
buf.set_string(area.x, y, &masked, base_style);
buf.set_string(area.x, y, &masked, Style::default());
}
}
}