]> git.proxmox.com Git - rustc.git/blob - vendor/prodash/src/render/tui/mod.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / vendor / prodash / src / render / tui / mod.rs
1 /*!
2 * A module implementing a *terminal user interface* capable of visualizing all information stored in
3 * [progress trees](../tree/struct.Root.html).
4 *
5 * **Please note** that it is behind the `render-tui` feature toggle, which is enabled by default.
6 *
7 * # Example
8 *
9 * ```should_panic
10 * # fn main() -> Result<(), Box<dyn std::error::Error>> {
11 * use futures::task::{LocalSpawnExt, SpawnExt};
12 * use prodash::render::tui::ticker;
13 * use prodash::Root;
14 * // obtain a progress tree
15 * let root = prodash::tree::Root::new();
16 * // Configure the gui, provide it with a handle to the ever-changing tree
17 * let render_fut = prodash::render::tui::render(
18 * std::io::stdout(),
19 * root.downgrade(),
20 * prodash::render::tui::Options {
21 * title: "minimal example".into(),
22 * ..Default::default()
23 * }
24 * )?;
25 * // As it runs forever, we want a way to stop it.
26 * let (render_fut, abort_handle) = futures::future::abortable(render_fut);
27 * let pool = futures::executor::LocalPool::new();
28 * // Spawn the gui into the background…
29 * let gui = pool.spawner().spawn_with_handle(async { render_fut.await.ok(); () })?;
30 * // …and run tasks which provide progress
31 * pool.spawner().spawn_local({
32 * use futures::StreamExt;
33 * let mut progress = root.add_child("task");
34 * async move {
35 * progress.init(None, None);
36 * let mut count = 0;
37 * let mut ticks = ticker(std::time::Duration::from_millis(100));
38 * while let Some(_) = ticks.next().await {
39 * progress.set(count);
40 * count += 1;
41 * }
42 * }
43 * })?;
44 * // …when we are done, tell the GUI to stop
45 * abort_handle.abort();
46 * //…and wait until it is done
47 * futures::executor::block_on(gui);
48 * # Ok(())
49 * # }
50 * ```
51 */
52 mod draw;
53 mod engine;
54 mod utils;
55
56 pub use engine::*;
57 /// Useful for bringing up the TUI without bringing in the `tui` crate yourself
58 pub use tui as tui_export;
59 pub use utils::ticker;