Skip to content

fix(forge_select): skip interactive prompts when stdin is not a terminal#2571

Merged
tusharmath merged 1 commit intomainfrom
terminal-check
Mar 16, 2026
Merged

fix(forge_select): skip interactive prompts when stdin is not a terminal#2571
tusharmath merged 1 commit intomainfrom
terminal-check

Conversation

@tusharmath
Copy link
Collaborator

@tusharmath tusharmath commented Mar 16, 2026

Summary

Skip interactive prompts in forge_select when stdin is not a terminal, preventing the process from blocking indefinitely in non-interactive sessions.

Context

When Forge runs in a non-interactive environment (e.g., piped input, CI pipelines, detached sessions), the interactive selection prompts (Select, MultiSelect, Input) attempt to read from stdin and block indefinitely since there is no terminal to interact with. This makes Forge unusable in scripted or automated workflows where stdin is not a TTY.

Changes

  • Added an is_terminal() check at the start of the prompt() method in all three interactive selection components:
    • InputBuilder::prompt - text input prompts
    • MultiSelectBuilder::prompt - multi-select (fzf-based) prompts
    • SelectBuilder::prompt - single-select (fzf-based) and confirm prompts
  • Each check returns Ok(None) immediately when stdin is not a terminal, allowing callers to handle the absence of user input gracefully

Key Implementation Details

Uses std::io::IsTerminal (stabilized in Rust 1.70) to detect whether stdin is connected to a terminal. The guard is placed as the very first check in each prompt() method, before any other logic (editor initialization, option validation, etc.), ensuring no resources are allocated unnecessarily.

Testing

# Verify interactive prompts still work normally in a terminal
cargo run

# Verify non-interactive behavior (should not hang)
echo "" | cargo test -p forge_select

# Run the crate tests
cargo test -p forge_select

@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Mar 16, 2026
@tusharmath tusharmath merged commit 635ba87 into main Mar 16, 2026
15 of 16 checks passed
@tusharmath tusharmath deleted the terminal-check branch March 16, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant