Crate minus[−][src]
Expand description
A fast, asynchronous terminal paging library for Rust. minus
provides high
level functions to easily embed a pager for any terminal application.
minus
can be used in asynchronous mode or in a blocking fashion
-
In asynchronous mode, the pager’s data as well as it’s configuration can be updated at any time.
minus
supports bothtokio
as well asasync-std
runtimes. The support for these runtimes are gated on individual features. -
In blocking mode, the pager stops any other code from being executed. This is good if you want to show some static information but it does not allow you to change the configuration of the pager at runtime.
-
When using
minus
, you select what features you need and nothing else.
Features
async_std_lib
: Use this if you useasync_std
runtime in your applicationtokio_lib
:Use this if you are usingtokio
runtime for your applicationstatic_output
: Use this if you only want to useminus
for displaying static outputsearch
: If you want searching capablities inside the feature
Examples
Print numbers 1 through 100 with 100ms delay in asynchronous mode
You can use any async runtime, but we are taking the example of tokio
use futures::join; use minus::{Pager, tokio_updating}; use std::{fmt::Write, time::Duration}; use tokio::time::sleep; #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let mut pager = Pager::new().unwrap(); pager.set_prompt("An asynchronous example"); let pager = pager.finish(); let updater = async { for i in 1..=100u8 { let mut guard = pager.lock().await; writeln!(guard, "{}", i)?; // Remember to drop the guard before any await or blocking operation drop(guard); sleep(Duration::from_millis(100)).await; } let mut guard = pager.lock().await; guard.end_data_stream(); Result::<_, std::fmt::Error>::Ok(()) }; let (res1, res2) = join!(tokio_updating(pager.clone()), updater); res1?; res2?; Ok(()) }
Print 1 through 100 in a blocking fashion (static output)
use std::fmt::Write; use minus::page_all; fn main() -> Result<(), Box<dyn std::error::Error>> { let mut pager = minus::Pager::new().unwrap(); for i in 1..=100 { writeln!(pager, "{}", i)?; } pager.set_prompt("Example"); minus::page_all(pager)?; Ok(()) }
Modules
Provides error types that are used in various places
Provides the InputHandler
trait, which can be used
to customize the default keybindings of minus
Structs
A struct containing all configurations for the pager.
Enums
Behaviour that happens when the pager is exitted
Enum indicating whether to display the line numbers or not.
search
Defines modes in which the search can run
Functions
async_std_lib
Run the pager inside an async_std task
.
static_output
Outputs static information.
tokio_lib
Run the pager inside a tokio task
.
Type Definitions
A convenience type for Vec<Box<dyn FnMut() + Send + Sync + 'static>>
tokio_lib
or async_std_lib
A convenience type for std::sync::Arc<async_mutex::Mutex<Pager>>