pub struct Live { /* private fields */ }Expand description
A list of steps redrawn in place as they run.
Steps can run one after another or at the same time: Step handles are cheap to clone
and can be moved to other threads, and every active step animates on its own. Steps can
have sub-steps (Step::step), and log prints a line above the display
without disturbing it.
A step is pending (○) until it starts, then ends done (●),
with a warning (▲) or failed (✕). It can also be
skipped (–), cancelled (⊘), or left waiting
on someone (◌), and a finished step can start again.
Beyond spinners and timings, a Live display does three things on its own:
- It learns. Each step’s duration is remembered between runs (see
remember_as). Next time, a step that would only have had a spinner gets a progress bar and an estimate:usually 42s · 18s left, orslower than usual. - It notices when you look away. In terminals that report window focus, animation
slows while you’re in another window. If a run of 10 seconds or more finishes while
you’re away, you get a desktop notification (
notify_after), and when you come back, the steps that finished meanwhile twinkle once so you can see them. - It stays out of the way of typing. Keys pressed during the run don’t scribble over
the display; they’re handed back to the shell when it ends, where the system allows it.
Linux 6.2 and later doesn’t by default (
dev.tty.legacy_tiocsti), so there they’re lost.
It draws on stdout, or stderr after set_target. When that isn’t a
terminal it does none of this and prints one plain line per finished
step, so CI logs stay readable. With Output::Json every change is
a JSON event instead, and with Output::Quiet only failures print.
Implementations§
Source§impl Live
impl Live
Sourcepub fn new(title: impl Into<String>, subject: impl Into<String>) -> Self
pub fn new(title: impl Into<String>, subject: impl Into<String>) -> Self
A live display headed title subject, e.g. deploy my-app → production: what’s
being done, and to what.
Nothing is drawn until the first step or log, so
everything chosen with the builder methods (fps,
remember_as, spinner and the rest) holds from
the first frame. Its clock starts here.
Examples found in repository?
11fn main() {
12 let fail = std::env::args().any(|a| a == "--fail");
13
14 // declaring every step up front shows the whole plan from the first frame
15 let live = Live::new("deploy", "my-app → production");
16 let build = live.step("Build");
17 let upload = live.step("Upload");
18 let release = live.step("Release");
19
20 build.start();
21 for file in ["main.rs", "config.rs", "assets"] {
22 build.detail(format!("compiling {file}"));
23 sleep(Duration::from_millis(400));
24 }
25 build.done();
26
27 upload.start();
28 for i in 1..=40 {
29 let f = i as f32 / 40.0;
30 upload.progress(f, format!("{:.1} / 12.0 MB", f * 12.0));
31 sleep(Duration::from_millis(40));
32 }
33 upload.done();
34
35 release.start();
36 sleep(Duration::from_millis(800));
37 if fail {
38 release.fail("the health check timed out after 30s");
39 live.finish_with_card(Card::failure("release failed").kv("logs", "my-app logs --since 5m"));
40 std::process::exit(1);
41 }
42 release.done();
43
44 let took = format!("in {:.1}s", live.elapsed().as_secs_f32());
45 live.finish_with_card(
46 Card::success("deployed")
47 .aside(&took)
48 .kv("url", "https://my-app.example.com"),
49 );
50}More examples
12fn main() {
13 tinsel::install_panic_hook();
14 if std::env::args().any(|a| a == "--json") {
15 tinsel::set_output(tinsel::Output::Json);
16 }
17
18 let live = Live::new("release", "v2.1.0");
19 let build = live.step("Build");
20 // sub-steps are drawn under their parent, and fold away once they've all passed
21 let targets: Vec<Step> = ["linux-x64", "linux-arm64", "macos-arm64"]
22 .into_iter()
23 .map(|t| build.step(t))
24 .collect();
25 let publish = live.step("Publish");
26
27 build.start();
28 // Step handles are cheap to clone and can move to other threads
29 scope(|s| {
30 for (i, target) in targets.iter().enumerate() {
31 s.spawn(move || {
32 target.start();
33 for stage in ["compiling", "linking", "stripping"] {
34 target.detail(stage);
35 sleep(Duration::from_millis(350 + 150 * i as u64));
36 }
37 if i == 2 {
38 // a line worth keeping, printed above the display without disturbing it
39 target.log("signed with Developer ID");
40 }
41 target.done();
42 });
43 }
44 });
45 build.done();
46
47 publish.start();
48 for i in 1..=30 {
49 let f = i as f32 / 30.0;
50 publish.progress(f, format!("{} of 3 archives", (f * 3.0).ceil()));
51 sleep(Duration::from_millis(40));
52 }
53 publish.done();
54
55 live.finish_with_card(Card::success("released").kv("tag", "v2.1.0"));
56}Sourcepub fn headless(title: impl Into<String>, subject: impl Into<String>) -> Self
pub fn headless(title: impl Into<String>, subject: impl Into<String>) -> Self
A display that never draws, on a clock that only moves when you call
advance, for checking what a run looks like in tests. Take a
snapshot whenever you want to see it. It keeps no history and
sends no notifications.
use std::time::Duration;
use tinsel::Live;
tinsel::set_color_mode(tinsel::ColorMode::None);
let live = Live::headless("deploy", "my-app");
let build = live.step("Build");
build.start();
live.advance(Duration::from_millis(1200));
build.done();
assert!(live.snapshot().plain().contains("● Build"));
assert!(live.snapshot().plain().ends_with("1.2s"));Sourcepub fn fps(self, fps: u32) -> Self
pub fn fps(self, fps: u32) -> Self
Draw this many frames a second, rather than fps for every display.
let live = tinsel::Live::new("deploy", "my-app").fps(120);Sourcepub fn no_focus(self) -> Self
pub fn no_focus(self) -> Self
Don’t listen for focus reports: no calmer animation while you’re away, no notification
when the run finishes, and stdin is left alone, for a tool that hands stdin to
something else. set_focus or the TINSEL_NO_FOCUS environment
variable does the same for every display.
let live = tinsel::Live::new("deploy", "my-app").no_focus();Sourcepub fn step(&self, label: impl Into<String>) -> Step
pub fn step(&self, label: impl Into<String>) -> Step
Add a pending step. Declaring every step up front shows the whole plan from the start.
Examples found in repository?
11fn main() {
12 let fail = std::env::args().any(|a| a == "--fail");
13
14 // declaring every step up front shows the whole plan from the first frame
15 let live = Live::new("deploy", "my-app → production");
16 let build = live.step("Build");
17 let upload = live.step("Upload");
18 let release = live.step("Release");
19
20 build.start();
21 for file in ["main.rs", "config.rs", "assets"] {
22 build.detail(format!("compiling {file}"));
23 sleep(Duration::from_millis(400));
24 }
25 build.done();
26
27 upload.start();
28 for i in 1..=40 {
29 let f = i as f32 / 40.0;
30 upload.progress(f, format!("{:.1} / 12.0 MB", f * 12.0));
31 sleep(Duration::from_millis(40));
32 }
33 upload.done();
34
35 release.start();
36 sleep(Duration::from_millis(800));
37 if fail {
38 release.fail("the health check timed out after 30s");
39 live.finish_with_card(Card::failure("release failed").kv("logs", "my-app logs --since 5m"));
40 std::process::exit(1);
41 }
42 release.done();
43
44 let took = format!("in {:.1}s", live.elapsed().as_secs_f32());
45 live.finish_with_card(
46 Card::success("deployed")
47 .aside(&took)
48 .kv("url", "https://my-app.example.com"),
49 );
50}More examples
12fn main() {
13 tinsel::install_panic_hook();
14 if std::env::args().any(|a| a == "--json") {
15 tinsel::set_output(tinsel::Output::Json);
16 }
17
18 let live = Live::new("release", "v2.1.0");
19 let build = live.step("Build");
20 // sub-steps are drawn under their parent, and fold away once they've all passed
21 let targets: Vec<Step> = ["linux-x64", "linux-arm64", "macos-arm64"]
22 .into_iter()
23 .map(|t| build.step(t))
24 .collect();
25 let publish = live.step("Publish");
26
27 build.start();
28 // Step handles are cheap to clone and can move to other threads
29 scope(|s| {
30 for (i, target) in targets.iter().enumerate() {
31 s.spawn(move || {
32 target.start();
33 for stage in ["compiling", "linking", "stripping"] {
34 target.detail(stage);
35 sleep(Duration::from_millis(350 + 150 * i as u64));
36 }
37 if i == 2 {
38 // a line worth keeping, printed above the display without disturbing it
39 target.log("signed with Developer ID");
40 }
41 target.done();
42 });
43 }
44 });
45 build.done();
46
47 publish.start();
48 for i in 1..=30 {
49 let f = i as f32 / 30.0;
50 publish.progress(f, format!("{} of 3 archives", (f * 3.0).ceil()));
51 sleep(Duration::from_millis(40));
52 }
53 publish.done();
54
55 live.finish_with_card(Card::success("released").kv("tag", "v2.1.0"));
56}Sourcepub fn log(&self, text: impl AsRef<str>)
pub fn log(&self, text: impl AsRef<str>)
Print a line above the display, which carries on drawing underneath it: for output
that’s worth keeping, like a warning from a compiler or a URL. Safe to call from any
thread. In plain output it’s an ordinary line; as JSON, a "log" event.
let live = tinsel::Live::new("build", "my-app");
live.log("using cached dependencies from yesterday");Sourcepub fn spinner(self, spinner: Spinner) -> Self
pub fn spinner(self, spinner: Spinner) -> Self
Choose how running steps animate (default: Spinner::Sparkle).
Sourcepub fn bar(self, bar: BarStyle) -> Self
pub fn bar(self, bar: BarStyle) -> Self
Choose how progress bars and estimates are drawn (default: BarStyle::Line).
use tinsel::{BarStyle, Live};
let live = Live::new("render", "intro.mp4").bar(BarStyle::Waveform);Sourcepub fn remember_as(self, name: impl Into<String>) -> Self
pub fn remember_as(self, name: impl Into<String>) -> Self
The name step timings are remembered under. Defaults to the program’s own name, which is right unless several programs share a name or one program wants separate histories. Steps are told apart by this name, the display’s title, and their label.
Timings live in $XDG_CACHE_HOME/tinsel (or ~/.cache/tinsel), one small file per
name. Only runs drawn on a terminal are recorded, and only steps that succeed.
timings shows what’s been learned.
Sourcepub fn no_history(self) -> Self
pub fn no_history(self) -> Self
Don’t remember step timings, or show estimates from earlier runs.
set_history or the TINSEL_NO_HISTORY environment variable
does the same for every display.
Sourcepub fn notify_after(self, after: Duration) -> Self
pub fn notify_after(self, after: Duration) -> Self
Send a desktop notification when the run finishes, if it took at least this long and the terminal window wasn’t focused at the time (default: 10 seconds).
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
How long since the display started, for a closing “done in 10.2s”.
Examples found in repository?
11fn main() {
12 let fail = std::env::args().any(|a| a == "--fail");
13
14 // declaring every step up front shows the whole plan from the first frame
15 let live = Live::new("deploy", "my-app → production");
16 let build = live.step("Build");
17 let upload = live.step("Upload");
18 let release = live.step("Release");
19
20 build.start();
21 for file in ["main.rs", "config.rs", "assets"] {
22 build.detail(format!("compiling {file}"));
23 sleep(Duration::from_millis(400));
24 }
25 build.done();
26
27 upload.start();
28 for i in 1..=40 {
29 let f = i as f32 / 40.0;
30 upload.progress(f, format!("{:.1} / 12.0 MB", f * 12.0));
31 sleep(Duration::from_millis(40));
32 }
33 upload.done();
34
35 release.start();
36 sleep(Duration::from_millis(800));
37 if fail {
38 release.fail("the health check timed out after 30s");
39 live.finish_with_card(Card::failure("release failed").kv("logs", "my-app logs --since 5m"));
40 std::process::exit(1);
41 }
42 release.done();
43
44 let took = format!("in {:.1}s", live.elapsed().as_secs_f32());
45 live.finish_with_card(
46 Card::success("deployed")
47 .aside(&took)
48 .kv("url", "https://my-app.example.com"),
49 );
50}Sourcepub fn advance(&self, by: Duration)
pub fn advance(&self, by: Duration)
Move a headless display’s clock on. Does nothing to a display on
real time.
Sourcepub fn snapshot(&self) -> Block
pub fn snapshot(&self) -> Block
The display as it looks right now, settled (no twinkles mid-way), with the header and
anything logged. Most useful with headless displays in tests.
Sourcepub fn timeline(&self) -> Block
pub fn timeline(&self) -> Block
When each step ran, as bars on one time axis, so you can see which steps overlapped and where the time went.
Build ━━━━━━━━━━━━━━━━━━ 2.3s
linux-arm64 ━━━━━━━━━━━━━━ 1.8s
linux-x64 ━━━━━━━━━━━━━━━━━━ 2.3s
Upload ━━━━━━━━━━━━ 1.6s
──────────────────────────────
0s 3.9sSourcepub fn finish_with_timeline(self)
pub fn finish_with_timeline(self)
Finish with a timeline under the steps.
Sourcepub fn finish(self)
pub fn finish(self)
Stop drawing and leave the final state on screen. Dropping a Live does the same.
Sourcepub fn finish_with_card(self, card: Card)
pub fn finish_with_card(self, card: Card)
Finish with a summary Card under the steps.
use tinsel::{Card, Live};
let live = Live::new("deploy", "my-app");
let build = live.step("Build");
build.start();
build.done();
live.finish_with_card(Card::success("deployed").kv("url", "https://my-app.example.com"));Examples found in repository?
11fn main() {
12 let fail = std::env::args().any(|a| a == "--fail");
13
14 // declaring every step up front shows the whole plan from the first frame
15 let live = Live::new("deploy", "my-app → production");
16 let build = live.step("Build");
17 let upload = live.step("Upload");
18 let release = live.step("Release");
19
20 build.start();
21 for file in ["main.rs", "config.rs", "assets"] {
22 build.detail(format!("compiling {file}"));
23 sleep(Duration::from_millis(400));
24 }
25 build.done();
26
27 upload.start();
28 for i in 1..=40 {
29 let f = i as f32 / 40.0;
30 upload.progress(f, format!("{:.1} / 12.0 MB", f * 12.0));
31 sleep(Duration::from_millis(40));
32 }
33 upload.done();
34
35 release.start();
36 sleep(Duration::from_millis(800));
37 if fail {
38 release.fail("the health check timed out after 30s");
39 live.finish_with_card(Card::failure("release failed").kv("logs", "my-app logs --since 5m"));
40 std::process::exit(1);
41 }
42 release.done();
43
44 let took = format!("in {:.1}s", live.elapsed().as_secs_f32());
45 live.finish_with_card(
46 Card::success("deployed")
47 .aside(&took)
48 .kv("url", "https://my-app.example.com"),
49 );
50}More examples
12fn main() {
13 tinsel::install_panic_hook();
14 if std::env::args().any(|a| a == "--json") {
15 tinsel::set_output(tinsel::Output::Json);
16 }
17
18 let live = Live::new("release", "v2.1.0");
19 let build = live.step("Build");
20 // sub-steps are drawn under their parent, and fold away once they've all passed
21 let targets: Vec<Step> = ["linux-x64", "linux-arm64", "macos-arm64"]
22 .into_iter()
23 .map(|t| build.step(t))
24 .collect();
25 let publish = live.step("Publish");
26
27 build.start();
28 // Step handles are cheap to clone and can move to other threads
29 scope(|s| {
30 for (i, target) in targets.iter().enumerate() {
31 s.spawn(move || {
32 target.start();
33 for stage in ["compiling", "linking", "stripping"] {
34 target.detail(stage);
35 sleep(Duration::from_millis(350 + 150 * i as u64));
36 }
37 if i == 2 {
38 // a line worth keeping, printed above the display without disturbing it
39 target.log("signed with Developer ID");
40 }
41 target.done();
42 });
43 }
44 });
45 build.done();
46
47 publish.start();
48 for i in 1..=30 {
49 let f = i as f32 / 30.0;
50 publish.progress(f, format!("{} of 3 archives", (f * 3.0).ceil()));
51 sleep(Duration::from_millis(40));
52 }
53 publish.done();
54
55 live.finish_with_card(Card::success("released").kv("tag", "v2.1.0"));
56}