feat: detect `os.Stdin`/`os.Stdout` redirection/pipe mode by smoyer64 · Pull Request #994 · git-bug/git-bug
In support of #831 and #993, this PR adds the ability to detect whether input is coming from the terminal or is being redirected/piped into the git-bug application as well as the corollary of output going to the terminal or being output to another application or file.
In general, there seem to be three categories of output for commands:
- Commands that have the same output regardless of how they're being used such as listing bugs in the JSON format.
- Commands that write the human readable portion of their output to
os.StdErrand the machine-readable portion of their output toos.StdOutsuch as the output when creating a new bug (the id of the new bug should be written to StdOut and the " created" suffix should be written to StdErr.) - Commands that need different behavior depending on whether the output is a terminal (presumably with a human watching) or to another application via redirection or piping (e.g. the adaptive terminal display with described in command: adapt the output of the bug list to the terminal size #993 where all line-oriented bug listings should be TSV if the output is redirected but should be prettier if shown to a user.)
All efforts should be made to create *nix friendly output using techniques 1 and 2 above - using TerminalIOMode and RedirectedOrPipedIOMode should be a last resort.
This PR also includes an equivalent feature for os.StdIn with the expectation that eventually commands such as bug new could read input from StdIn instead of an editor with the existing behavior for separating the title and description (comment index 0).
References #828.