-
Notifications
You must be signed in to change notification settings - Fork 83
Description
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 inget_real_output())