From 3ce9780b903fda75d8982cf435dd541c7d026779 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Fri, 7 Nov 2025 16:08:58 -0800 Subject: [PATCH 1/2] fix(tui): Fail is stdin is not a terminal Piping to codex fails to do anything useful and locks up the process. We currently check for stdout, but not stdin --- codex-rs/tui/src/tui.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/codex-rs/tui/src/tui.rs b/codex-rs/tui/src/tui.rs index 39849471b5..d691009149 100644 --- a/codex-rs/tui/src/tui.rs +++ b/codex-rs/tui/src/tui.rs @@ -1,6 +1,8 @@ +use std::io; use std::io::IsTerminal; use std::io::Result; use std::io::Stdout; +use std::io::stdin; use std::io::stdout; use std::pin::Pin; use std::sync::Arc; @@ -84,8 +86,8 @@ impl Command for EnableAlternateScroll { } #[cfg(windows)] - fn execute_winapi(&self) -> std::io::Result<()> { - Err(std::io::Error::other( + fn execute_winapi(&self) -> io::Result<()> { + Err(io::Error::other( "tried to execute EnableAlternateScroll using WinAPI; use ANSI instead", )) } @@ -105,8 +107,8 @@ impl Command for DisableAlternateScroll { } #[cfg(windows)] - fn execute_winapi(&self) -> std::io::Result<()> { - Err(std::io::Error::other( + fn execute_winapi(&self) -> io::Result<()> { + Err(io::Error::other( "tried to execute DisableAlternateScroll using WinAPI; use ANSI instead", )) } @@ -131,8 +133,11 @@ pub fn restore() -> Result<()> { /// Initialize the terminal (inline viewport; history stays in normal scrollback) pub fn init() -> Result { + if !stdin().is_terminal() { + return Err(io::Error::other("stdin is not a terminal")); + } if !stdout().is_terminal() { - return Err(std::io::Error::other("stdout is not a terminal")); + return Err(io::Error::other("stdout is not a terminal")); } set_modes()?; @@ -490,7 +495,7 @@ impl Tui { } } - std::io::stdout().sync_update(|_| { + stdout().sync_update(|_| { #[cfg(unix)] { if let Some(prepared) = prepared_resume.take() { @@ -605,8 +610,8 @@ impl Command for PostNotification { } #[cfg(windows)] - fn execute_winapi(&self) -> std::io::Result<()> { - Err(std::io::Error::other( + fn execute_winapi(&self) -> io::Result<()> { + Err(io::Error::other( "tried to execute PostNotification using WinAPI; use ANSI instead", )) } From 7ef30dcb1c11597157587773cb5f0f9f12f9f360 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Thu, 13 Nov 2025 10:04:42 -0800 Subject: [PATCH 2/2] undo removal of std:: prefix to reduce PR noise --- codex-rs/tui/src/tui.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/codex-rs/tui/src/tui.rs b/codex-rs/tui/src/tui.rs index d691009149..2b4e67e6af 100644 --- a/codex-rs/tui/src/tui.rs +++ b/codex-rs/tui/src/tui.rs @@ -1,4 +1,3 @@ -use std::io; use std::io::IsTerminal; use std::io::Result; use std::io::Stdout; @@ -86,8 +85,8 @@ impl Command for EnableAlternateScroll { } #[cfg(windows)] - fn execute_winapi(&self) -> io::Result<()> { - Err(io::Error::other( + fn execute_winapi(&self) -> std::io::Result<()> { + Err(std::io::Error::other( "tried to execute EnableAlternateScroll using WinAPI; use ANSI instead", )) } @@ -107,8 +106,8 @@ impl Command for DisableAlternateScroll { } #[cfg(windows)] - fn execute_winapi(&self) -> io::Result<()> { - Err(io::Error::other( + fn execute_winapi(&self) -> std::io::Result<()> { + Err(std::io::Error::other( "tried to execute DisableAlternateScroll using WinAPI; use ANSI instead", )) } @@ -134,10 +133,10 @@ pub fn restore() -> Result<()> { /// Initialize the terminal (inline viewport; history stays in normal scrollback) pub fn init() -> Result { if !stdin().is_terminal() { - return Err(io::Error::other("stdin is not a terminal")); + return Err(std::io::Error::other("stdin is not a terminal")); } if !stdout().is_terminal() { - return Err(io::Error::other("stdout is not a terminal")); + return Err(std::io::Error::other("stdout is not a terminal")); } set_modes()?; @@ -610,8 +609,8 @@ impl Command for PostNotification { } #[cfg(windows)] - fn execute_winapi(&self) -> io::Result<()> { - Err(io::Error::other( + fn execute_winapi(&self) -> std::io::Result<()> { + Err(std::io::Error::other( "tried to execute PostNotification using WinAPI; use ANSI instead", )) }