MultiSpinner

Struct MultiSpinner 

Source
pub struct MultiSpinner { /* private fields */ }
Expand description

struct holding multiple spinners

§Single Spinner Example

use std::thread::sleep;
use std::time::Duration;
use zenity::spinner::{Frames, MultiSpinner};

let spinner = MultiSpinner::default();
spinner.run_all();

sleep(Duration::from_secs(4));
// do work here...

// get last created uid
spinner.set_text(&spinner.get_last(), "spinner1".to_string());

// no need to stop the spinners they will run out of scope and get dropped

Implementations§

Source§

impl MultiSpinner

use std::thread::sleep;
use std::time::Duration;
use zenity::spinner::{Frames, MultiSpinner};

let spinner = MultiSpinner::default();
let spinner1 = spinner.get_last();
let spinner2 = spinner.add(Frames::default()); // this already returns the uid

spinner.run_all();
sleep(Duration::from_secs(4));

spinner.set_text(&spinner1, "spinner1".to_string());

spinner.stop(&spinner1); // stop the spinner1

spinner.set_text(&spinner2, "spinner2 :3".to_string());

// no need to stop spinner2 #
Source

pub fn new() -> Self

creates a new MultiSpinner instance

§Example
use zenity::spinner::MultiSpinner;
let spinner = MultiSpinner::new();
Source

pub fn add(&self, frames: Frames) -> usize

create a new spinner

§Returns

unique identifier

§Example
use zenity::spinner::MultiSpinner;
use zenity::spinner::Frames;

let spinner = MultiSpinner::new();

spinner.add(Frames::aesthetic_load());
Source

pub fn get_last(&self) -> usize

get the last create uid

§Returns

unique identifier of the last created spinner

§Example
use zenity::spinner::MultiSpinner;
use zenity::spinner::Frames;

let spinner = MultiSpinner::new();
spinner.add(Frames::default());

// the return values is an id you will need to edit the spinner later on
let spinner1_uid = spinner.get_last();
Source

pub fn clear(&self, rows: Option<u16>)

Sets the number of rows to clear in the terminal before starting the animation. If no value is provided, the terminal will clear all rows by default, effectively clearing the screen without deleting old content, which might leave empty rows.

§Example
use zenity::spinner::MultiSpinner;
use zenity::spinner::Frames;

let spinner = MultiSpinner::new();

// Clear with the default number of rows (entire terminal)
spinner.add(Frames::default());

// Clear with a specified number of rows (12)
spinner.clear(Some(12));

// Dont Clean anything
spinner.clear(None);

spinner.run_all()
§Parameters
  • rows: An optional u16 specifying the number of rows to clear. If None, no rows will be cleared.
Source

pub fn set_text(&self, uid: &usize, new_text: String)

set text of a specific spinner

if the uid is invalid, this does nothing

§Example
use zenity::spinner::MultiSpinner;
use zenity::spinner::Frames;
use zenity::style::StyledString;

let spinner = MultiSpinner::default();

spinner.set_text(&spinner.get_last(),"example".to_string());
Source

pub fn set_styled_text(&self, uid: &usize, new_text: StyledString)

set a styled text of a specific spinner

if the uid is invalid, this does nothing

§Example
use crossterm::style::Color;
use zenity::spinner::MultiSpinner;
use zenity::spinner::Frames;
use zenity::style::StyledString;

let spinner = MultiSpinner::default();

spinner.set_styled_text(&spinner.get_last(),
    StyledString::simple("test string", Some(Color::Red), Some(Color::Black), None));
Source

pub fn stop(&self, uid: &usize)

stops a spinner if the uid is invalid this does nothing

§Example
use zenity::spinner::MultiSpinner;
use zenity::spinner::Frames;

let spinner = MultiSpinner::default();

spinner.stop(&spinner.get_last());
Source

pub fn show_line_number(&self)

shows the line number of the running spinners

[1/4] .¸¸¸¸¸¸¸¸

§Example
use zenity::spinner::MultiSpinner;
use zenity::spinner::Frames;

let spinner = MultiSpinner::default();

spinner.show_line_number();
Source

pub fn run_all(&self)

execute all created spinners

§Example
use zenity::spinner::MultiSpinner;
use zenity::spinner::Frames;

// make spinner mutable
let mut spinner = MultiSpinner::default();

// queue spinners for execution
let spinner_num1 = spinner.get_last();
let spinner_num2 = spinner.add(Frames::dots_simple_big1());

//start the spinners
spinner.run_all();

Trait Implementations§

Source§

impl Clone for MultiSpinner

Source§

fn clone(&self) -> MultiSpinner

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for MultiSpinner

Source§

fn default() -> Self

creates a new Progress instance

§Example
use zenity::spinner::MultiSpinner;
let spinner = MultiSpinner::default();
Source§

impl Drop for MultiSpinner

Source§

fn drop(&mut self)

stops the loading animation thread when the LoadingAnimation object is dropped

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.