Skip to content

Implement TTY detection so progress bar is not shown unless in a TTY environment #327

@AndrewRayCode

Description

@AndrewRayCode

Hello, thank you for the workaround for the progress bar bugs with SFDX_USE_PROGRESS_BAR=false. However this is not a robust solution and is anti-shell-ecosystem.

In shell scripting, we of course send output with stdout and stderr.

Some tools give nice progress indicators of status, for example, docker pull:

Screen Shot 2020-03-02 at 10 06 49 AM

Now, to draw a progress bar and refresh the view so that it updates in shell scripting, you need to send special characters to do things like overwrite the current line to implement animation that updates.

Of course this is only done in a "TTY" environment, my understanding is short for "teletype" - referencing old physical machines you type at, really for me this means interactive, as in accepting user input.

There are lots of times where a program isn't sending output to an interactive terminal. The most common one you've probably used is piping commands to another command. Let's take a look at what docker pull does when you pipe the output to another program:

Screen Shot 2020-03-02 at 10 09 39 AM

You can see docker correctly detects it's not in an interactive environment, and correctly writes text with newlines to stdout.

All programs that output animation type behavior to stdio have this default detection behavior. This is a requirement for a program to run and play nicely in this ecosystem. You can see this behavior with any other command that has some sort of progress indicator or screen refreshing mechanism.

Where this probably matters most for sfdx users is running sfdx on ci systems, where of course the stdout isn't in an interactive terminal where users can type. Sending clear or overwrite characters to this terminal is incorrect behavior because there's nothing to clear, we're just capturing text from stdout and stderr and showing it to the user. This will of course also be an issue if I want to capture the output of sfdx and do things like grep it, unless I know to use this magic workaround switch.

I have seen some pushback from library maintainers, and I feel worried that SFDX_USE_PROGRESS_BAR will be cemented as a "solution", when in fact this is a workaround that makes sfdx a little harder for everyone to use. I don't think sfdx should forever have inconsistent behavior compared to all other shell tools that have updating behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions