From 28f8da5ce99fd82606da28d896d27ba6b4085120 Mon Sep 17 00:00:00 2001 From: no382001 <102482527+no382001@users.noreply.github.com> Date: Tue, 31 Mar 2026 21:13:40 +0200 Subject: [PATCH] restructure based on suggestion MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Co-authored-by: Bennet Bleßmann <3877590+Skgland@users.noreply.github.com> --- src/machine/streams.rs | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/machine/streams.rs b/src/machine/streams.rs index a2ac58a4..94a9b34d 100644 --- a/src/machine/streams.rs +++ b/src/machine/streams.rs @@ -657,27 +657,20 @@ impl Stream { #[inline] pub fn stdin(arena: &mut Arena, add_history: bool) -> Stream { - if std::io::stdin().is_terminal() { - Stream::Readline(arena_alloc!( - StreamLayout::new(ReadlineStream::new("", add_history)), - arena - )) - } else { - #[cfg(unix)] - { - use std::os::unix::io::{FromRawFd, RawFd}; - // dup fd 0 so the File can be owned (and closed later) without - // closing the real stdin. - let fd = unsafe { libc::dup(0 as RawFd) }; - let file = unsafe { File::from_raw_fd(fd) }; - return Stream::from_file_as_input(atom!("user_input"), file, arena); - } - #[allow(unreachable_code)] - Stream::Readline(arena_alloc!( - StreamLayout::new(ReadlineStream::new("", add_history)), - arena - )) + #[cfg(unix)] + if !std::io::stdin().is_terminal() { + use std::os::unix::io::{FromRawFd, RawFd}; + // dup fd 0 so the File can be owned (and closed later) without + // closing the real stdin. + let fd = unsafe { libc::dup(0 as RawFd) }; + let file = unsafe { File::from_raw_fd(fd) }; + return Stream::from_file_as_input(atom!("user_input"), file, arena); } + + Stream::Readline(arena_alloc!( + StreamLayout::new(ReadlineStream::new("", add_history)), + arena + )) } pub fn from_tag(tag: ArenaHeaderTag, ptr: UntypedArenaPtr) -> Self { -- 2.54.0