Crate tokio_pager

Crate tokio_pager 

Source
Expand description

Asynchronous, Tokio-friendly pager implementation.

Unfortunately, Rust’s pager crate does not play nicely with Tokio. It leaves threads open after the Tokio runtime exits, resulting in a nasty I/O error after a CLI program using both pager and a Tokio runtime exits. This may be due to the fact that the pager crate actually runs the pager in the parent process, meaning that the Tokio runtime, in the child process, exits before the pager, leaving dangling file descriptors and the aforementioned I/O error from Tokio.

There isn’t a great away to customize the behavior of the pager crate, so this module implements a Pager struct that allows the use of a pager subprocess in a way that plays nicely with Tokio.

Pager pipes its output to program specified in the $PAGER environment variable, except under two conditions:

  1. If the value of $PAGER is cat, /usr/bin/cat, or anything that ends in /cat (/bin/cat, etc.), then the output is not paged at all (cat is not launched).
  2. If stdout is not a TTY, such as when output is being redirected to a file, the output is not paged.

Pager respects the value of the $LESS environment variable (with some caveats—see PagerEnv::pager_env() for details).

Right now, Pager is also designed specifically to work with less, so it does not make use of any other environment variables, but support for other pagers may expand in the future.

Structs§

Pager
A Tokio-friendly asynchronous pager.
PagerEnv
Retrieves the pager and pager configuration from the environment.

Type Aliases§

EnvVar
An environmental variable consisting of a name-value pair.
Result
A result from the pager subprocess.