Skip to content

CLI capabilities detection does not respect the active app #144

@tzakharko

Description

@tzakharko

The package offers a number of functions to detect the CLI capabilities, however, it is not straightforward to detect the capabilities of the active output connection. For instance, in my scripts I usually set the cli output to stdout (makes it easier to capture output):

 cli::start_app(output = "stdout")

In real usage, stdout may be proper terminal output, or it could be redirected to a file or another app. Being able to detect the capability of the actual output connection is important here, as the script could adjust it's output appropriately (e.g. avoid using animations when we are redirecting the output to the file).

Hovewer, cli_output_connection() still returns the default stderr so functions like is_ansi_tty() and is_dynamic_tty() do not work out of box. Even more, they still don't work if you do something like is_dynamic_tty(default_app()$output), since they expect a connection object and not a string. Now, the following does works

is_dynamic_tty(cli::: get_real_output(default_app()$output))

but its unnecessary verbose and relies on internal package symbols.

My suggestion to improve this:

  • either change cli_output_connection() to respect the default app (might be a breaking change though)
  • patch is_ansi_tty(), is_dynamic_tty() etc. to work with string stream descriptions (hooking in get_real_output())

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions