pager

Pipe long command output through the user’s preferred pager.

The public entry point is page, which decides whether to spawn a pager or print directly to stdout based on a fixed policy:

  1. Stdout is not a TTY → print directly
  2. The user passed --no-pager → print directly
  3. pager.enabled = false in config → print directly
  4. The resolved pager command is empty → print directly
  5. The content fits on screen (lines ≤ terminal_rows - 1) → print directly
  6. 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

source

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

source

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

source

fn resolve_pager(config_command: Option<&str>) -> String

Resolve the pager command using the documented precedence.

Order, highest to lowest:

  1. config_command (the pager.command config value) when non-empty
  2. $GEST_PAGER when non-empty
  3. $PAGER when non-empty
  4. 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

source

fn should_page(
    line_count: usize,
    no_pager: bool,
    enabled: bool,
    is_tty: bool,
    terminal_rows: Option<u16>,
) -> bool

Decide 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.