diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs index 4723361c25..6b7017f6f0 100644 --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs @@ -712,7 +712,11 @@ impl WidgetRef for &ChatComposer<'_> { Span::from(" to quit"), ] } else { - let newline_hint = if crate::tui::is_kkp_enabled() { "Shift+⏎" } else { "Ctrl+J" }; + let newline_hint = if crate::tui::is_kkp_enabled() { + "Shift+⏎" + } else { + "Ctrl+J" + }; vec![ Span::from(" "), "⏎".set_style(key_hint_style), @@ -962,6 +966,9 @@ mod tests { use ratatui::Terminal; use ratatui::backend::TestBackend; + // First, run snapshots with KKP enabled so hints show Shift+⏎. + crate::tui::set_kkp_for_tests(true); + let (tx, _rx) = std::sync::mpsc::channel(); let sender = AppEventSender::new(tx); let mut terminal = match Terminal::new(TestBackend::new(100, 10)) { @@ -1006,6 +1013,18 @@ mod tests { assert_snapshot!(name, terminal.backend()); } + + // Also add one snapshot with KKP disabled so we still see Ctrl+J. + crate::tui::set_kkp_for_tests(false); + let mut terminal_ctrlj = match Terminal::new(TestBackend::new(100, 10)) { + Ok(t) => t, + Err(e) => panic!("Failed to create terminal: {e}"), + }; + let composer = ChatComposer::new(true, sender.clone()); + terminal_ctrlj + .draw(|f| f.render_widget_ref(&composer, f.area())) + .unwrap_or_else(|e| panic!("Failed to draw empty_ctrlj composer: {e}")); + assert_snapshot!("empty_ctrlj", terminal_ctrlj.backend()); } #[test] diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__empty_ctrlj.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__empty_ctrlj.snap new file mode 100644 index 0000000000..f798f1af16 --- /dev/null +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__empty_ctrlj.snap @@ -0,0 +1,14 @@ +--- +source: tui/src/bottom_pane/chat_composer.rs +expression: terminal_ctrlj.backend() +--- +"▌ ... " +"▌ " +"▌ " +"▌ " +"▌ " +"▌ " +"▌ " +"▌ " +"▌ " +" ⏎ send Ctrl+J newline Ctrl+C quit " diff --git a/codex-rs/tui/src/tui.rs b/codex-rs/tui/src/tui.rs index e57b94fc72..ea8dbe69c5 100644 --- a/codex-rs/tui/src/tui.rs +++ b/codex-rs/tui/src/tui.rs @@ -27,6 +27,11 @@ pub(crate) fn is_kkp_enabled() -> bool { KKP_ENABLED.load(Ordering::Relaxed) } +#[cfg(test)] +pub(crate) fn set_kkp_for_tests(value: bool) { + KKP_ENABLED.store(value, Ordering::Relaxed); +} + /// Try to detect Kitty Keyboard Protocol support by issuing a progressive /// enhancement query and waiting briefly for a response. #[cfg(unix)]