General output formatting (was: Re: \b character escapes in CLI usage)
From: Marc Branchaud <hidden>
Date: 2025-02-27 14:06:56
On 2025-02-26 19:03, Junio C Hamano wrote:
"brian m. carlson" [off-list ref] writes:quoted
I agree this is the right choice in general. I wonder if we might want some sort of human-readable output option that might escape these that users could use. The output might still be machine-readable, ...I wonder if isatty(1) is a good way to say "ah, we are not captured in 'foo=$(git blah)' and not feeding somebody in 'git blah | somebody', so we do not have to worry about being machine readable". If that is a reliable way to tell that we could butcher our output for the sake of keeping the terminal state sane, we then can always do the C-quote escaping, or even information losing '?' redaction.
Modern practice seems to be moving towards explicit format options to let code that's parsing output directly specify how it wants to see the data. Such options eliminate the need for isatty() heuristics and other guesswork. For example, the ip command (at least in Ubuntu) accepts -j to format output as JSON. I've found this to be immensely helpful for my scripts. I'm sure Git scripters would appreciate something similar, perhaps as a global "--format=X" option to "git" itself. isatty() heuristics could still be used when no formatting option is specified (though I suspect in the long run the default will end up being terminal-friendly output). This would certainly be a large effort, but once the basic pattern is worked out it could be incrementally implemented one command at a time. M.