Help_Command::pass_through_pager()private staticWP-CLI 1.0

Method of the class: Help_Command{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = Help_Command::pass_through_pager( $out );
$out (required)
-

Help_Command::pass_through_pager() code WP-CLI 2.8.0-alpha

private static function pass_through_pager( $out ) {

	if ( ! Utils\check_proc_available( null /*context*/, true /*return*/ ) ) {
		WP_CLI::line( $out );
		WP_CLI::debug( 'Warning: check_proc_available() failed in pass_through_pager().', 'help' );
		return -1;
	}

	$pager = getenv( 'PAGER' );
	if ( false === $pager ) {
		$pager = Utils\is_windows() ? 'more' : 'less -r';
	}

	// For Windows 7 need to set code page to something other than Unicode (65001) to get around "Not enough memory." error with `more.com` on PHP 7.1+.
	if ( 'more' === $pager && defined( 'PHP_WINDOWS_VERSION_MAJOR' ) && PHP_WINDOWS_VERSION_MAJOR < 10 && function_exists( 'sapi_windows_cp_set' ) ) {
		// Note will also apply to Windows 8 (see https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832.aspx) but probably harmless anyway.
		$cp = getenv( 'WP_CLI_WINDOWS_CODE_PAGE' ) ?: 1252; // Code page 1252 is the most used so probably the most compat.
		// phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions -- Wrapped in function_exists() call.
		sapi_windows_cp_set( $cp ); // `sapi_windows_cp_set()` introduced PHP 7.1.
	}

	// Convert string to file handle.
	$fd = fopen( 'php://temp', 'r+b' );
	fwrite( $fd, $out );
	rewind( $fd );

	$descriptorspec = [
		0 => $fd,
		1 => STDOUT,
		2 => STDERR,
	];

	return proc_close( Utils\proc_open_compat( $pager, $descriptorspec, $pipes ) );
}