Crate minus[−][src]
Expand description
minus
is a terminal paging library for Rust. It provides high
level functions to easily embed a pager for any terminal application without
requiring you to think about the nitty-gritty of building a pager.
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 both
tokio
as well as async-std
runtimes. These runtimes are gated
on specific features.
In blocking mode, the pager stops any other task 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.
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
Note: You must select a either a runtime feature or static_output
. If you do not
select any features when adding minus
to Cargo.toml
, it will not have any functions
to start a pager.
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()?;
pager.set_prompt("An asynchronous example");
let pager_mutex = pager.finish();
let updater = async {
for i in 1..=100u8 {
let mut guard = pager_mutex.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_mutex.lock().await;
guard.end_data_stream();
Result::<_, std::fmt::Error>::Ok(())
};
let (res1, res2) = join!(tokio_updating(pager_mutex.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 InputClassifier
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 convenient type for Vec<Box<dyn FnMut() + Send + Sync + 'static>>
tokio_lib
or async_std_lib
A convenient type for std::sync::Arc<async_mutex::Mutex<Pager>>