19 unstable releases

0.16.1 Sep 22, 2022
0.16.0 Nov 8, 2020
0.15.0 Sep 26, 2018
0.14.0 Dec 11, 2017
0.9.4 Nov 10, 2016

#102 in Text processing

Download history 1345/week @ 2023-11-20 1515/week @ 2023-11-27 1036/week @ 2023-12-04 1456/week @ 2023-12-11 1266/week @ 2023-12-18 710/week @ 2023-12-25 1285/week @ 2024-01-01 1431/week @ 2024-01-08 1300/week @ 2024-01-15 1237/week @ 2024-01-22 1437/week @ 2024-01-29 1568/week @ 2024-02-05 1562/week @ 2024-02-12 1761/week @ 2024-02-19 1796/week @ 2024-02-26 1833/week @ 2024-03-04

7,099 downloads per month
Used in 33 crates (32 directly)

Apache-2.0/MIT

16KB
238 lines

Pager - long output best friend

Build Status Crates.io Docs.rs

Does all the magic to have you potentially long output piped through the external pager. Similar to what git does for its output.

Quick Start

extern crate pager;

use pager::Pager;

fn main() {
    Pager::new().setup();
    // The rest of your program goes here
}

Under the hood this forks the current process, connects child' stdout to parent's stdin, and then replaces the parent with the pager of choice (environment variable PAGER). The child just continues as normal. If PAGER environment variable is not present Pager probes current PATH for more. If found it is used as a default pager.

You can control pager to a limited degree. For example you can change the environment variable used for finding pager executable.

extern crate pager;

use pager::Pager;

fn main() {
    Pager::with_env("MY_PAGER").setup();
    // The rest of your program goes here
}

Also you can set alternative default (fallback) pager to be used instead of more. PAGER environment variable (if set) will still have precedence.

extern crate pager;

use pager::Pager;

fn main() {
    Pager::with_default_pager("pager").setup();
    // The rest of your program goes here
}

If no suitable pager found setup() does nothing and your executable keeps running as usual. Pager cleans after itself and doesn't leak resources in case of setup failure.

Alternatively you can specify directly the desired pager command, exactly as it would appear in PAGER environment variable. This is useful if you need some specific pager and/or flags (like "less -r") and would like to avoid forcing your consumers into modifying their existing PAGER configuration just for your application.

extern crate pager;
use pager::Pager;
fn main() {
    Pager::with_pager("less -r").setup();
    // The rest of your program goes here
}

Sometimes you may want to bypass pager if the output of you executable is not a tty. If this case you may use .skip_on_notty() to get the desirable effect.

extern crate pager;
use pager::Pager;
fn main() {
    Pager::new().skip_on_notty().setup();
    // The rest of your program goes here
}

If you need to disable pager altogether set environment variable NOPAGER and Pager::setup() will skip initialization. The host application will continue as normal. Pager::is_on() will reflect the fact that no Pager is active.

Dependencies

~230KB