Expand description
This crate provides functionality to pipe terminal output through a pager
program (like less or more) on Unix-like systems. It is designed to be
used in command-line applications that generate large amounts of output,
allowing users to scroll through the content conveniently.
The primary entry point is the Pager builder, which allows for configuration
and ultimately spawns a pager process via the spawn() method. The returned
PagerSession struct handles the lifecycle of the pager process. When the
PagerSession is dropped, it gracefully terminates the pager and restores
the original standard output.
This functionality is only active on Unix-like systems and when the output is being sent to an interactive terminal. On Windows or in non-interactive sessions, it gracefully becomes a no-op.
§Usage
use mago_pager::Pager;
// Spawn a pager if the environment is suitable.
let _session = Pager::new().spawn()?;
// All subsequent writes to stdout will be piped to the pager.
println!("This line goes to the pager.");
println!("So does this one.");
// When `_session` goes out of scope, the pager is closed and stdout is restored.§Environment Variables
PAGER: Overrides the default pager command.NOPAGER: If set to any value, disables the pager entirely.
Structs§
- Pager
- A builder for configuring and spawning a terminal pager.
- Pager
Session - Represents an active pager session.
Constants§
- DEFAULT_
PAGER - The fallback pager command if no other is specified.
- DEFAULT_
PAGER_ ENV - Environment variable to specify a custom pager command.
- NOPAGER_
ENV - Environment variable to disable the pager.