pub struct Step { /* private fields */ }Expand description
A handle to one step of a Live display. Cheap to clone and safe to move to other threads.
Implementations§
Source§impl Step
impl Step
Sourcepub fn step(&self, label: impl Into<String>) -> Step
pub fn step(&self, label: impl Into<String>) -> Step
Add a pending sub-step, drawn indented under this one. Once a step and all its sub-steps have succeeded, the sub-steps fold away; if any warned or failed, they stay.
let live = tinsel::Live::new("release", "v2.1.0");
let build = live.step("Build");
let (linux, mac) = (build.step("linux"), build.step("macos"));
build.start();
for target in [&linux, &mac] {
target.start();
target.done();
}
build.done();Examples found in repository?
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 start(&self)
pub fn start(&self)
Mark the step as running: its spinner starts and its timer begins. If it has run before, its usual duration is looked up so it can show an estimate.
A step that has finished, failed or been waiting can start again, like a job that’s retried: its timer starts over, and only its last run is remembered.
let live = tinsel::Live::new("deploy", "my-app");
let upload = live.step("Upload");
upload.start();
upload.fail("connection reset");
upload.start();
upload.done();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 detail(&self, text: impl Into<String>)
pub fn detail(&self, text: impl Into<String>)
A dim sub-line under the active step, e.g. what it’s working on right now.
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 progress(&self, fraction: f32, text: impl Into<String>)
pub fn progress(&self, fraction: f32, text: impl Into<String>)
Show a progress bar under the active step; text sits beside the percentage. A step
that reports its own progress doesn’t show an estimate. The fraction is kept between 0
and 1, and NaN (from dividing by a total of 0, say) counts as 0.
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, labelled with this step: see Live::log.
Examples found in repository?
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 done(&self)
pub fn done(&self)
Mark the step as finished. Its mark twinkles, then settles into ●.
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 warn(&self, note: impl Into<String>)
pub fn warn(&self, note: impl Into<String>)
Mark the step as finished with something worth a look, shown as a note under it.
Sourcepub fn fail(&self, note: impl Into<String>)
pub fn fail(&self, note: impl Into<String>)
Mark the step as failed, with the reason shown under it.
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 skip(&self, reason: impl Into<String>)
pub fn skip(&self, reason: impl Into<String>)
Mark the step as skipped: it didn’t run and won’t. The reason, if not empty, shows under it. Skipped steps aren’t trouble, so they fold away with their parent.
let live = tinsel::Live::new("check", "my-app");
live.step("Lint").skip("no source files changed");Sourcepub fn cancel(&self, reason: impl Into<String>)
pub fn cancel(&self, reason: impl Into<String>)
Mark the step as cancelled: stopped, or never started, because someone called it off rather than because it failed. The reason, if not empty, shows under it.
let live = tinsel::Live::new("deploy", "my-app");
let upload = live.step("Upload");
upload.start();
upload.cancel("stopped by hand");Sourcepub fn wait(&self, on: impl Into<String>)
pub fn wait(&self, on: impl Into<String>)
Mark the step as waiting on someone or something, said under it, with how long it’s
been waiting on the right. start it once it can go on. Waiting is
worth noticing, so it prints in quiet output too.
let live = tinsel::Live::new("deploy", "my-app → production");
let release = live.step("Release");
release.wait("waiting for approval");
// … once someone approves
release.start();
release.done();Sourcepub fn try_run<T, E: Display>(
&self,
f: impl FnOnce() -> Result<T, E>,
) -> Result<T, E>
pub fn try_run<T, E: Display>( &self, f: impl FnOnce() -> Result<T, E>, ) -> Result<T, E>
Run f as this step: started if it hasn’t been, then done on Ok or failed on Err,
with the error as its note.
let live = tinsel::Live::new("deploy", "my-app");
live.step("Load config").try_run(load_config)?;§Errors
Whatever f fails with, once the step is marked failed with it.
Sourcepub fn retry<T, E: Display>(
&self,
retries: u32,
f: impl FnMut() -> Result<T, E>,
) -> Result<T, E>
pub fn retry<T, E: Display>( &self, retries: u32, f: impl FnMut() -> Result<T, E>, ) -> Result<T, E>
Like try_run, but on Err tries again, up to retries more times,
waiting a little longer each time (0.5s, 1s, 2s, … up to 8s). The step’s detail shows
which attempt it’s on. Succeeding after a retry ends on a warning, so flaky steps
get noticed.
§Errors
The last attempt’s error, once every retry has failed too.
Sourcepub fn run<'c>(
&self,
command: impl BorrowMut<Command> + Send + Sync + 'c,
) -> Result<String, RunError>
pub fn run<'c>( &self, command: impl BorrowMut<Command> + Send + Sync + 'c, ) -> Result<String, RunError>
Run a command as this step, showing its latest line of output as the step’s detail. Done if it exits successfully; otherwise failed, with its last lines of output under it. Returns everything it printed (stdout and stderr together).
use std::process::Command;
let live = tinsel::Live::new("build", "my-app");
let output = live.step("Compile").run(Command::new("cargo").arg("build"))?;The command can be handed over, or lent as &mut Command as above. It reads nothing
(see StepCommand::stdin), and its output is collected, so a lent command keeps
those settings afterwards.
For a timeout, retries or input, use command.
§Errors
A RunError if the command can’t be started or exits unsuccessfully.
Sourcepub fn command<'c>(
&self,
command: impl BorrowMut<Command> + Send + Sync + 'c,
) -> StepCommand<'_, 'c>
pub fn command<'c>( &self, command: impl BorrowMut<Command> + Send + Sync + 'c, ) -> StepCommand<'_, 'c>
A command to run as this step, with options: see StepCommand.