Struct minus::Pager[][src]

pub struct Pager { /* fields omitted */ }
Expand description

A struct containing basic configurations for the pager. This is used by all initializing functions

Example

You can use any async runtime, but we are taking the example of tokio

 #[tokio::main]
 async fn main() -> Result<(), Box<dyn std::error::Error>> {
     use minus::{Pager, LineNumbers, tokio_updating};
     let mut pager = Pager::new().unwrap();
     pager.set_line_numbers(LineNumbers::AlwaysOn);
     pager.set_prompt("A complex configuration");

     // Normally, you would use `futures::join` to join the pager and the text
     // updating function. We are doing this here to make the example simple
     tokio_updating(pager.finish()).await?;
     Ok(())
 }

For static output

 fn main() -> Result<(), Box<dyn std::error::Error>> {
      let mut pager = minus::Pager::new().unwrap();
      pager.set_text("Hello");
      pager.set_prompt("Example");
      minus::page_all(pager)?;
      Ok(())
 }

Implementations

Initialize a new pager configuration

Errors

This function will return an error if it cannot determine the terminal size

Example

let pager = minus::Pager::new().unwrap();

Set the output text to this t

Note that unlike Pager::push_str, this replaces the original text. If you want to append text, use the Pager::push_str function

Example

let mut pager = minus::Pager::new().unwrap();
pager.set_text("This is a line");

Set line number to this setting

Example

use minus::{Pager, LineNumbers};

let mut pager = Pager::new().unwrap();
pager.set_line_numbers(LineNumbers::Enabled);

Set the prompt displayed at the prompt to t

Example

use minus::Pager;

let mut pager = Pager::new().unwrap();
pager.set_prompt("my awesome program");
This is supported on crate features tokio_lib or async_std_lib only.

Return a PagerMutex from this Pager. This is gated on tokio_lib or async_std_lib feature

Example

use minus::Pager;

let mut pager = Pager::new().unwrap();
pager.set_text("This output is paged");
let _pager_mutex = pager.finish();

Set the default exit strategy.

This controls how the pager will behave when the user presses q or Ctrl+C. See ExitStrategy for available options

use minus::{Pager, ExitStrategy};

let mut pager = Pager::new().unwrap();
pager.set_exit_strategy(ExitStrategy::ProcessQuit);

Set whether to display pager if there’s less data than available screen height

By default this is set to false

use minus::Pager;

let mut pager = Pager::new().unwrap();
pager.set_run_no_overflow(true);

Appends text to the pager output

This function will automatically split the lines, if they overflow the number of terminal columns

let mut pager = minus::Pager::new().unwrap();
pager.push_str("This is some text");

Hints the running pager that no more data is coming

Example

use minus::Pager;

let mut pager = Pager::new().unwrap();
pager.set_text("Hello from minus!");
pager.end_data_stream();

Set custom input handler function

See example in InputHandler on using this function

Example

use minus::Pager;

fn hello() {
    println!("Hello");
}

let mut pager = Pager::new().unwrap();
pager.add_exit_callback(Box::new(hello));

Trait Implementations

Returns the “default value” for a type. Read more

Writes a string slice into this writer, returning whether the write succeeded. Read more

Writes a char into this writer, returning whether the write succeeded. Read more

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.