Fix #194: Allow --version/--help to run without TTY access #324
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #194
Problem:
Running
edit --version
oredit --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:
sys::init()
to perform only minimal setup for default stdio handles (makingsys::write_stdout()
functional) without trying to open/dev/tty
.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.main.rs
to:sys::init()
.--version
or--help
arguments. If present, print the info and exit (this path now bypasses the/dev/tty
logic).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:
edit --version
andedit --help
with piped stdin (e.g.,echo "test" | ./target/release/edit --version
) now execute successfully and print the correct output.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.