fix(stdin): show TTY hint when reading from interactive terminal#146
Open
Emp1500 wants to merge 1 commit into
Open
fix(stdin): show TTY hint when reading from interactive terminal#146Emp1500 wants to merge 1 commit into
Emp1500 wants to merge 1 commit into
Conversation
When a user runs a command with "-" as the file path from an interactive terminal (e.g. design.md lint -), the process blocks silently waiting for EOF with no indication of what to do. Add a TTY check before the stdin read loop. If stdin is attached to a terminal, write to stderr: Reading from stdin… Press Ctrl+D when done. The stdin stream is accepted as an optional second parameter on readInput (defaulting to process.stdin), making the TTY path fully testable via dependency injection without touching process.stdin directly. Also exports StdinStream so callers can type mock streams without duplicating the definition.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When a user runs a
design.mdcommand with-as the file path from aninteractive terminal, the process hangs silently with no output:
There is no indication that the tool is waiting for input, or that the user must press
Ctrl+Dto signal end-of-file. A user unfamiliar with this Unix convention has no feedback to distinguish a stalled process from one that is working correctly.Root Cause
readInputreads stdin viafor await (const chunk of process.stdin)with no TTY detection. When stdin is an interactive terminal(
process.stdin.isTTY === true), the loop blocks until EOF — but nothing prompts the user to send one.Solution
Before entering the read loop, check whether stdin is a TTY and, if so, emit a one-line hint to
stderr:Piped usage is completely unaffected —
isTTYisfalsefor pipes, so the hint never appears and existing behavior is unchanged:Design Decisions
readInputnow accepts an optionalstdinstream parameter that defaults toprocess.stdin. All existing call sites remain unchanged.StdinStreamis exported so test files can type mock streams without duplicating the interface definition.Changes
utils.tsStdinStreamtype; add optionalstdinparam toreadInput; add TTY check before read looputils.test.ts