Skip to content

Fix #194: Allow --version/--help to run without TTY access #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Nihal-Pandey-2302
Copy link

Fixes #194

Problem:
Running edit --version or edit --help failed in environments where /dev/tty was unavailable and stdin was not a TTY, because the application attempted to open /dev/tty during initial system setup.

Solution:
This PR implements the approach suggested by @lhecker in the issue comments:

  • Modified sys::init() to perform only minimal setup for default stdio handles (making sys::write_stdout() functional) without trying to open /dev/tty.
  • Introduced a new sys::ensure_interactive_tty() function. This function now contains the logic to check if stdin is a TTY and, if necessary for interactive mode, opens /dev/tty and updates the relevant system state.
  • Adjusted main.rs to:
    1. Call the modified sys::init().
    2. Check for --version or --help arguments. If present, print the info and exit (this path now bypasses the /dev/tty logic).
    3. If not an early exit, call sys::ensure_interactive_tty() before proceeding with full editor initialization.

This ensures that --version and --help can execute without needing full TTY access, while interactive mode still correctly sets up the TTY.

Testing Done:

  • Verified that edit --version and edit --help with piped stdin (e.g., echo "test" | ./target/release/edit --version) now execute successfully and print the correct output.
  • Confirmed that normal editor operations are unaffected:
    • edit (opens new file)
    • edit <filename> (opens existing file)
    • echo "content" | ./target/release/edit (correctly ingests piped content while allowing interactive TTY control).
      All local tests passed.

Modified sys::init to perform minimal setup for default stdio handles.
Introduced sys::ensure_interactive_tty to handle TTY-specific setup
only when entering interactive mode, per @lhecker's suggestion.
This allows --version and --help commands to execute successfully
without requiring /dev/tty access.
@Nihal-Pandey-2302
Copy link
Author

@microsoft-github-policy-service agree

@lhecker
Copy link
Member

lhecker commented May 29, 2025

We're not sure about the approach you've taken and will need longer to decide on whether to adopt this or not. I apologize for the wait.

@Nihal-Pandey-2302
Copy link
Author

No worries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Running without a TTY causes --version / --help to fail
2 participants