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
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.
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
Writes a string slice into this writer, returning whether the write succeeded. Read more
Auto Trait Implementations
impl !RefUnwindSafe for Pager
impl !UnwindSafe for Pager