Skip to main content

Step

Struct Step 

Source
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

Source

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?
examples/parallel.rs (line 23)
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}
Source

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?
examples/deploy.rs (line 20)
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
Hide additional examples
examples/parallel.rs (line 27)
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}
Source

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?
examples/deploy.rs (line 22)
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
Hide additional examples
examples/parallel.rs (line 34)
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}
Source

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?
examples/deploy.rs (line 30)
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
Hide additional examples
examples/parallel.rs (line 50)
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}
Source

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?
examples/parallel.rs (line 39)
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}
Source

pub fn done(&self)

Mark the step as finished. Its mark twinkles, then settles into ●.

Examples found in repository?
examples/deploy.rs (line 25)
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
Hide additional examples
examples/parallel.rs (line 41)
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}
Source

pub fn warn(&self, note: impl Into<String>)

Mark the step as finished with something worth a look, shown as a note under it.

Source

pub fn fail(&self, note: impl Into<String>)

Mark the step as failed, with the reason shown under it.

Examples found in repository?
examples/deploy.rs (line 38)
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}
Source

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");
Source

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");
Source

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();
Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Step

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Step

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Step

§

impl Freeze for Step

§

impl Move for Step

§

impl RefUnwindSafe for Step

§

impl Send for Step

§

impl Sync for Step

§

impl Unpin for Step

§

impl UnsafeUnpin for Step

§

impl UnwindSafe for Step

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.