[][src]Module prodash::tui

A module implementing a terminal user interface capable of visualizing all information stored in progress trees.

Please note that it is behind the tui-renderer feature toggle, which is enabled by default.

Example

use futures::task::{LocalSpawnExt, SpawnExt};
use prodash::tui::ticker;
// obtain a progress tree
let root = prodash::Tree::new();
// Configure the gui, provide it with a handle to the ever-changing tree
let render_fut = prodash::tui::render(
    root.clone(),
    prodash::tui::TuiOptions {
        title: "minimal example".into(),
        ..prodash::tui::TuiOptions::default()
    }
)?;
// As it runs forever, we want a way to stop it.
let (render_fut, abort_handle) = futures::future::abortable(render_fut);
let pool = futures::executor::LocalPool::new();
// Spawn the gui into the background…
let gui = pool.spawner().spawn_with_handle(async { render_fut.await.ok(); () })?;
// …and run tasks which provide progress
pool.spawner().spawn_local({
    use futures::StreamExt;
    let mut progress = root.add_child("task");
    async move {
        progress.init(None, Some("items"));
        let mut count = 0;
        let  mut ticks = ticker(std::time::Duration::from_millis(100));
        while let Some(_) = ticks.next().await {
            progress.set(count);
            count += 1;
        }
    }
})?;
// …when we are done, tell the GUI to stop
abort_handle.abort();
//…and wait until it is done
futures::executor::block_on(gui);

Re-exports

pub use tui as tui_export;

Structs

TuiOptions

Configure the terminal user interface

Enums

Event

An event to be sent in the tui::render_with_input(…events) stream.

Interrupt

The variants represented here allow the user to control when the GUI can be shutdown.

Line

A line as used in Event::SetInformation

Functions

render

An easy-to-use version of render_with_input(…) that does not allow state manipulation via an event stream.

render_with_input

Returns a future that draws the terminal user interface indefinitely.

ticker

Returns a stream of 'ticks', each being duration dur apart.