Skip to main content

spinner

Function spinner 

Source
pub fn spinner(name: impl Into<String>) -> Spinner
Available on crate features print and process only.
Expand description

Display child process’s status as a progress bar spinner.

§Example

Spawn a git-clone process, and use a spinner to show progress updates.

use cu::pre::*;

cu::which("git")?.command()
    .args(["clone", "--progress", "https://example1.git"])
    // stdout should be empty, but if there are any messages,
    // we will print them
    .stdout(cu::lv::P)
    // use spinner to show the bar
    .stderr(cu::pio::spinner("cloning example1"))
    .stdin_null()
    .spawn()?.0
    .wait_nz()?;

§Behavior

The stream is splited into lines by \r and \n (\r\n is turned into single \n). If the line ends with \r, it’s considered a progress update.

By default, no matter if the line ends with \r, the bar will be updated with the line. You can also configure the bar to only display updates (end with \r), and print the other messages (end with \n) as normal messages.

use cu::pre::*;

cu::which("git")?.command()
    .args(["clone", "--progress", "https://example1.git"])
    // feed both stdout and stderr into the same bar
    // when a progress update is done, it will also be printed as
    // an info message
    .stdoe(cu::pio::spinner("cloning example1").info())
    .stdin_null()
    .spawn()?.0
    .wait_nz()?;

§Output

The progress bar handle is returned when you spawn the child. If the stdout and stderr are configured to the same spinner, then either handle can be used to update the bar.