1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//! Clean terminal output for Rust CLIs, with a little sparkle.
//!
//! ```no_run
//! use tinsel::prelude::*;
//!
//! let live = Live::new("deploy", "my-app → production");
//! let build = live.step("Build package");
//! let upload = live.step("Upload bundle");
//!
//! build.start();
//! build.detail("bundling 412 files");
//! build.done();
//!
//! upload.start();
//! upload.progress(0.5, "17 / 34 MB");
//! upload.done();
//!
//! live.finish_with_card(Card::success("deployed").kv("url", "https://my-app.example.com"));
//! ```
//!
//! # What's here
//!
//! | | |
//! |---|---|
//! | **live work** | [`Live`] step lists with sub-steps, parallel steps and [`Live::log`]; a [`Region`] redrawing any block; commands run as steps ([`Step::run`], [`Step::command`]) and [`Step::retry`]; a [`Live::timeline`] of where the time went; [`spin`] / [`try_spin`] around one task; a standalone [`Progress`] bar or [`ProgressIterator`] around any loop, drawn as a line or a [`BarStyle::Waveform`]; seven [`Spinner`]s |
//! | **messages** | [`success`], [`info`], [`warn`], [`error`], [`hint`], [`counter`], [`title`], [`rule`], [`callout`], [`Report`] |
//! | **data** | [`Table`] (sorting, borders, wrapping, footers), [`Tree`], [`pairs`], [`columns`] |
//! | **charts** | [`sparkline`], [`bars`], [`meter`], [`histogram`], [`heatmap`], [`waveform`] |
//! | **code** | [`diff`], [`Code`] excerpts with syntax colouring ([`Lang`]) and carets under the problem |
//! | **documents** | [`markdown`], [`json`], [`Help`] (with an entrance), and [`Block::page`] for anything long |
//! | **inline** | [`badge`], [`link`], [`Card`], [`paint`], [`bold`] and friends |
//! | **apps** | [`app`]: full-screen dashboards and tools, with [`app::Panel`]s, [`app::List`]s, [`app::ScrollView`]s, [`app::Tabs`], [`app::Plot`]s, [`app::Stat`]s, [`app::Loading`] and [`app::big`] text laid out in [`app::Rect`]s; [`app::snapshot`] to test them |
//! | **questions** | [`prompt`]: confirm, input (validation, suggestions, path completion), password, number, date, select and multiselect (filter as you type, headings, disabled options), a dropdown for long lists, editor, confirm by typing; `.back()` to go back a question |
//! | **helpers** | [`text`] (width-aware pad, truncate, wrap) and [`format`](mod@format) (bytes, durations, ago) |
//! | **setup** | [`install_panic_hook`], [`set_output`] for `--json` and `--quiet`, [`set_target`] to draw on stderr, [`set_accent`], [`set_theme`], [`set_color_mode`], [`set_focus`] and [`set_history`], [`timings`] |
//!
//! # How the pieces fit
//!
//! - **One-liners print.** [`success`], [`warn`] and the rest print straight away. Use a
//! [`Tone`] when you want the line as a string instead.
//! - **Everything bigger is a [`Block`].** Tables, trees, cards, callouts, diffs: you can
//! `.print()` them, `println!("{}")` them, or call `.plain()` for unstyled text.
//! - **Builders for anything with options.** [`Table`], [`Tree`], [`Card`], [`Report`] and
//! [`Code`] are built up with chained methods, so call sites read like what they draw.
//! - **Questions return a [`prompt::Result`],** whose [`prompt::Error`] tells cancelling apart
//! from having no terminal.
//!
//! # Output for programs, and quiet output
//!
//! [`set_output`] switches everything at once: [`Output::Json`] turns every message, step,
//! report and block into one JSON object per line, for tools reading your output, and
//! [`Output::Quiet`] keeps only what needs attention (warnings, errors, failures and anything
//! printed explicitly). `TINSEL_OUTPUT=json` or `quiet` does the same from outside.
//!
//! # Colour, terminals and tests
//!
//! tinsel draws in truecolor when `COLORTERM` says the terminal supports it, otherwise in
//! 256 colours. It respects `NO_COLOR`, and when stdout isn't a terminal (CI, a pipe, a log
//! file) it drops colour and animation and writes plain lines like `[ok] Build (1.2s)`.
//!
//! Everything is drawn on stdout unless [`set_target`] (or `TINSEL_TARGET=stderr`) moves it
//! to stderr, for tools whose stdout carries something else; then it's stderr that has to
//! be a terminal.
//!
//! Animations draw 60 frames a second. [`set_fps`] (or `TINSEL_FPS`) changes that for the
//! whole program, and a display can choose its own: `Live::fps`, `Progress::fps`, `App::fps`.
//!
//! [`set_color_mode`] overrides all of that, for a `--color` flag or to get predictable text
//! in tests:
//!
//! ```
//! tinsel::set_color_mode(tinsel::ColorMode::None);
//! let table = tinsel::Table::new(["app", "size"]).row(["core", "34 MB"]);
//! assert_eq!(table.lines().plain().lines().last(), Some(" core 34 MB"));
//! ```
//!
//! [`Live::headless`] gives you a display on a clock you move yourself, so you can check
//! exactly what a run looks like at each point with [`Live::snapshot`].
//!
//! To test your own program's output, [`capture`] returns everything a closure prints
//! through tinsel, as it would come out into a pipe, and [`with_color_mode`] picks a colour
//! mode for one closure on one thread, so a test that checks colour codes doesn't change
//! them for the tests running beside it.
pub use Block;
pub use ;
pub use doctor;
pub use ;
pub use Help;
pub use Lang;
pub use set_history;
pub use ;
pub use ;
pub use ;
pub use markdown;
pub use ;
pub use notify;
pub use ;
pub use install_panic_hook;
pub use Region;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Tree;
pub use set_focus;
pub use ;
/// What [`Live`] displays have learned about how long steps take, as a table per program:
/// recent runs as a sparkline, the usual time, the last run, and whether it was unusually
/// slow or fast. Pass a name given to [`Live::remember_as`] (or a program's own name), or
/// `None` for every program with history.
///
/// ```no_run
/// tinsel::timings(Some("my-app")).print();
/// ```
///
/// ```text
/// my-app
/// step recent usual last trend
/// ─────────────────────────────────────────────────────
/// Build ▃▃▄▃▃▄▃█ 41.2s 1m12s 74% slower
/// Upload ▅▄▅▅▄▅▅▄ 8.1s 7.9s steady
/// ```
/// The things most CLIs reach for, in one import: `use tinsel::prelude::*;`