minus

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

Usage

In your Cargo.toml file ```toml [dependencies.minus] version = "^1.0"

For tokio

features = ["tokio_lib"]

For async_std

features = ["asyncstdlib"]

For static output

features = ["static_output"] ```

Example

Using tokio

``` rust use tokio::main; use futures::join; use std::sync::{Arc, Mutex};

[main]

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;

[main]

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

Contributing

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