pager
The public entry point is page, which decides whether to spawn a pager
or print directly to stdout based on a fixed policy:
- Stdout is not a TTY → print directly
- The user passed
--no-pager→ print directly pager.enabled = falsein config → print directly- The resolved pager command is empty → print directly
- The content fits on screen (
lines ≤ terminal_rows - 1) → print directly - Otherwise spawn the pager and pipe content to its stdin
On any spawn or terminal-size failure the helper falls back to a direct print so output is never lost.
const DEFAULT_PAGER
const DEFAULT_PAGER: &str = "less -R";Default pager invocation when neither config nor environment specifies one.
less -R passes ANSI escapes through unchanged so colored output renders
correctly when paged.
fn page
pub fn page(content: &str, context: &AppContext) -> Result<()>Pipe content through the user’s preferred pager when the policy allows it.
See the module docs for the full decision order. The function never errors on a missing or broken pager: any spawn or write failure falls back to printing the content directly to stdout.
| Parameter | Type | Description |
|---|---|---|
content |
&str | the text to show |
context |
&AppContext | the app context, for --no-pager and the [pager] settings |
| returns | Result<()> | Ok(()) once the content is printed or the pager exits, or an error when waiting for the pager fails. |
fn resolve_pager
fn resolve_pager(config_command: Option<&str>) -> StringResolve the pager command using the documented precedence.
Order, highest to lowest:
config_command(thepager.commandconfig value) when non-empty$GEST_PAGERwhen non-empty$PAGERwhen non-empty- The hard-coded
DEFAULT_PAGER
| Parameter | Type | Description |
|---|---|---|
config_command |
Option<&str> | the pager.command config value, if any |
| returns | String | The pager command line to run. |
fn should_page
fn should_page(
line_count: usize,
no_pager: bool,
enabled: bool,
is_tty: bool,
terminal_rows: Option<u16>,
) -> boolDecide whether the configured policy allows spawning a pager.
terminal_rows is None when terminal_size could not detect the
terminal height; in that case the height check is skipped (i.e. assumed to
require paging) so that interactive output is not silently swallowed.
| Parameter | Type | Description |
|---|---|---|
line_count |
usize | the number of lines of output |
no_pager |
bool | whether --no-pager was passed |
enabled |
bool | the pager.enabled config value |
is_tty |
bool | whether stdout is a terminal |
terminal_rows |
Option<u16> | the terminal height, or None when it is unknown |
| returns | bool | true when output goes to a terminal, paging is not turned off, and the content does not fit on screen or the terminal height is unknown. |