Source code for dbx_python_cli.utils.output
"""Output utilities for formatting and pagination."""
import shutil
import subprocess
import sys
import typer
[docs]
def paginate_output(output: str, use_pager: bool = False):
"""Display output using a pager if requested and available.
Args:
output: The text to display
use_pager: Whether to use a pager (from -p flag or command default)
The function will use 'less -R' if:
- use_pager is True
- stdout is a terminal (not piped)
- 'less' is available on the system
Otherwise, it will print directly to stdout.
"""
# Only paginate if explicitly requested and stdout is a terminal
if use_pager and sys.stdout.isatty() and shutil.which("less"):
subprocess.run(["less", "-R"], input=output, text=True)
else:
typer.echo(output)