A fast, asynchronous terminal paging library for Rust. Minus provides a high level functions to easily write a pager for any terminal application Due to the asynchronous nature, data to the pager can be updated. It supports both tokio as well as async-std runtimes. Plus if you only to use minus for serving static output, you can simply opt out of these dynamic features
Minus was started by me as my work on pijul. I had dissatisfaction with all existing options like pager and moins
Pager:-
more
or less
Moins
tokio
for your application, use the tokio_lib
featureasync_std
for your application, use the async_std_lib
featurestatic_output
featureIn your Cargo.toml
file
```toml
[dependencies.minus]
version = "^1.0"
features = ["tokio_lib"]
features = ["asyncstdlib"]
features = ["static_output"] ```
Using tokio
``` rust use tokio::main; use futures::join; use std::sync::{Arc, Mutex};
async fn main() { let output = Arc::new(Mutex::new(String::new())); // Asynchronously push numbers to a string let increment = async { for i in 0..100 { let guard = output.lock().unwrap(); // Always use writeln to add a \n after the line let _ = writeln!(output, "{}", guard); // Drop here explicitly, if you have further asynchronous blocking code drop(guard); // Some asynchronous blocking code tokio::task::sleep(std::Duration::new(1,0)).await; } } join!(minus::tokio_updating(output.clone()), increment); } ```
Using async_std
```rust use async_std::main; use futures::join; use std::sync::{Arc, Mutex}; use std::fmt::Write;
async fn main() { let output = Arc::new(Mutex::new(String::new())); // Asynchronously push numbers to a string let increment = async { for i in 0..100 { let guard = output.lock().unwrap(); // Always use writeln to add a \n after the line let _ = writeln!(output, "{}", guard); // Drop here explicitly, if you have further asynchronous blocking code drop(guard); // Some asynchronous blocking code asyncstd::task::sleep(std::Duration::new(1,0)).await; } } join!(minus::asyncstd_updating(output.clone()), increment); } ```
Some static output ``` rust use std::fmt::Write;
fn main() { let mut output = String::new(); for i in 1..=100 { let _ = writeln!(output, "{}", i); } minus::page_all(output); } ```
If there are more rows in the terminal than the number of lines in the given data. Minus will simply print the data and quit. This only works in static paging only
Issues, pull requests are more than welcome Unless explicitly stated otherwise, all works to minus are dual licensed under the MIT and Apache License 2.0
See CONTRIBUTING.md on how to contribute to minus
See the licenses in their respective files