Struct throbber_widgets_tui::widgets::Throbber

source ·
pub struct Throbber<'a> { /* private fields */ }
Expand description

A compact widget to display a throbber.

A throbber may also be called:

  • activity indicator
  • indeterminate progress bar
  • loading icon
  • spinner
  • guru guru

§Examples:

let throbber = throbber_widgets_tui::Throbber::default()
    .throbber_style(ratatui::style::Style::default().fg(ratatui::style::Color::White).bg(ratatui::style::Color::Black))
    .label("NOW LOADING...");
// frame.render_widget(throbber, chunks[0]);
let throbber_state = throbber_widgets_tui::ThrobberState::default();
// frame.render_stateful_widget(throbber, chunks[0], &mut throbber_state);

Implementations§

source§

impl<'a> Throbber<'a>

source

pub fn label<T>(self, label: T) -> Self
where T: Into<Span<'a>>,

Examples found in repository?
examples/demo.rs (line 113)
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
fn ui(f: &mut ratatui::Frame, app: &mut App) {
    let all_sets = [
        ("ASCII", throbber_widgets_tui::ASCII),
        ("BOX_DRAWING", throbber_widgets_tui::BOX_DRAWING),
        ("ARROW", throbber_widgets_tui::ARROW),
        ("DOUBLE_ARROW", throbber_widgets_tui::DOUBLE_ARROW),
        ("VERTICAL_BLOCK", throbber_widgets_tui::VERTICAL_BLOCK),
        ("HORIZONTAL_BLOCK", throbber_widgets_tui::HORIZONTAL_BLOCK),
        ("QUADRANT_BLOCK", throbber_widgets_tui::QUADRANT_BLOCK),
        (
            "QUADRANT_BLOCK_CRACK",
            throbber_widgets_tui::QUADRANT_BLOCK_CRACK,
        ),
        ("WHITE_SQUARE", throbber_widgets_tui::WHITE_SQUARE),
        ("WHITE_CIRCLE", throbber_widgets_tui::WHITE_CIRCLE),
        ("BLACK_CIRCLE", throbber_widgets_tui::BLACK_CIRCLE),
        ("CLOCK", throbber_widgets_tui::CLOCK),
        ("BRAILLE_ONE", throbber_widgets_tui::BRAILLE_ONE),
        ("BRAILLE_SIX", throbber_widgets_tui::BRAILLE_SIX),
        ("BRAILLE_EIGHT", throbber_widgets_tui::BRAILLE_EIGHT),
        ("BRAILLE_DOUBLE", throbber_widgets_tui::BRAILLE_DOUBLE),
        (
            "BRAILLE_SIX_DOUBLE",
            throbber_widgets_tui::BRAILLE_SIX_DOUBLE,
        ),
        (
            "BRAILLE_EIGHT_DOUBLE",
            throbber_widgets_tui::BRAILLE_EIGHT_DOUBLE,
        ),
        ("OGHAM_A", throbber_widgets_tui::OGHAM_A),
        ("OGHAM_B", throbber_widgets_tui::OGHAM_B),
        ("OGHAM_C", throbber_widgets_tui::OGHAM_C),
        ("PARENTHESIS", throbber_widgets_tui::PARENTHESIS),
        ("CANADIAN", throbber_widgets_tui::CANADIAN),
    ];
    let horizontal_num = 4;
    // why +1? because the first line is for title default throbber.
    let vertical_num = 1 + (all_sets.len() + horizontal_num - 1) / horizontal_num;
    let verticals = ratatui::layout::Layout::default()
        .direction(ratatui::layout::Direction::Vertical)
        .constraints(&vec![ratatui::layout::Constraint::Length(1); vertical_num])
        .split(f.area());
    let default_throbber = throbber_widgets_tui::Throbber::default()
        .label("Press q to exit. This line is a default throbber (random step). The followings are incremental step.")
        .style(ratatui::style::Style::default().fg(ratatui::style::Color::Yellow));
    f.render_widget(default_throbber, verticals[0]);

    let mut chunks: Option<_> = None;
    for (i, kvp) in all_sets.iter().enumerate() {
        let (name, set) = kvp;
        let row = i / horizontal_num;
        let col = i % horizontal_num;
        if col == 0 {
            chunks = Some(
                ratatui::layout::Layout::default()
                    .direction(ratatui::layout::Direction::Horizontal)
                    .constraints(&vec![
                        ratatui::layout::Constraint::Percentage(
                            100 / (horizontal_num as u16)
                        );
                        horizontal_num
                    ])
                    .split(verticals[row + 1]),
            );
        }
        if app.states.len() <= i {
            app.states
                .push(throbber_widgets_tui::ThrobberState::default());
        }
        let throbber = throbber_widgets_tui::Throbber::default()
            .label(name.to_string())
            .throbber_set(set.clone());
        f.render_stateful_widget(throbber, chunks.clone().unwrap()[col], &mut app.states[i]);
    }
}
source

pub fn style(self, style: Style) -> Self

Examples found in repository?
examples/demo.rs (line 114)
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
fn ui(f: &mut ratatui::Frame, app: &mut App) {
    let all_sets = [
        ("ASCII", throbber_widgets_tui::ASCII),
        ("BOX_DRAWING", throbber_widgets_tui::BOX_DRAWING),
        ("ARROW", throbber_widgets_tui::ARROW),
        ("DOUBLE_ARROW", throbber_widgets_tui::DOUBLE_ARROW),
        ("VERTICAL_BLOCK", throbber_widgets_tui::VERTICAL_BLOCK),
        ("HORIZONTAL_BLOCK", throbber_widgets_tui::HORIZONTAL_BLOCK),
        ("QUADRANT_BLOCK", throbber_widgets_tui::QUADRANT_BLOCK),
        (
            "QUADRANT_BLOCK_CRACK",
            throbber_widgets_tui::QUADRANT_BLOCK_CRACK,
        ),
        ("WHITE_SQUARE", throbber_widgets_tui::WHITE_SQUARE),
        ("WHITE_CIRCLE", throbber_widgets_tui::WHITE_CIRCLE),
        ("BLACK_CIRCLE", throbber_widgets_tui::BLACK_CIRCLE),
        ("CLOCK", throbber_widgets_tui::CLOCK),
        ("BRAILLE_ONE", throbber_widgets_tui::BRAILLE_ONE),
        ("BRAILLE_SIX", throbber_widgets_tui::BRAILLE_SIX),
        ("BRAILLE_EIGHT", throbber_widgets_tui::BRAILLE_EIGHT),
        ("BRAILLE_DOUBLE", throbber_widgets_tui::BRAILLE_DOUBLE),
        (
            "BRAILLE_SIX_DOUBLE",
            throbber_widgets_tui::BRAILLE_SIX_DOUBLE,
        ),
        (
            "BRAILLE_EIGHT_DOUBLE",
            throbber_widgets_tui::BRAILLE_EIGHT_DOUBLE,
        ),
        ("OGHAM_A", throbber_widgets_tui::OGHAM_A),
        ("OGHAM_B", throbber_widgets_tui::OGHAM_B),
        ("OGHAM_C", throbber_widgets_tui::OGHAM_C),
        ("PARENTHESIS", throbber_widgets_tui::PARENTHESIS),
        ("CANADIAN", throbber_widgets_tui::CANADIAN),
    ];
    let horizontal_num = 4;
    // why +1? because the first line is for title default throbber.
    let vertical_num = 1 + (all_sets.len() + horizontal_num - 1) / horizontal_num;
    let verticals = ratatui::layout::Layout::default()
        .direction(ratatui::layout::Direction::Vertical)
        .constraints(&vec![ratatui::layout::Constraint::Length(1); vertical_num])
        .split(f.area());
    let default_throbber = throbber_widgets_tui::Throbber::default()
        .label("Press q to exit. This line is a default throbber (random step). The followings are incremental step.")
        .style(ratatui::style::Style::default().fg(ratatui::style::Color::Yellow));
    f.render_widget(default_throbber, verticals[0]);

    let mut chunks: Option<_> = None;
    for (i, kvp) in all_sets.iter().enumerate() {
        let (name, set) = kvp;
        let row = i / horizontal_num;
        let col = i % horizontal_num;
        if col == 0 {
            chunks = Some(
                ratatui::layout::Layout::default()
                    .direction(ratatui::layout::Direction::Horizontal)
                    .constraints(&vec![
                        ratatui::layout::Constraint::Percentage(
                            100 / (horizontal_num as u16)
                        );
                        horizontal_num
                    ])
                    .split(verticals[row + 1]),
            );
        }
        if app.states.len() <= i {
            app.states
                .push(throbber_widgets_tui::ThrobberState::default());
        }
        let throbber = throbber_widgets_tui::Throbber::default()
            .label(name.to_string())
            .throbber_set(set.clone());
        f.render_stateful_widget(throbber, chunks.clone().unwrap()[col], &mut app.states[i]);
    }
}
source

pub fn throbber_style(self, style: Style) -> Self

source

pub fn throbber_set(self, set: Set) -> Self

Examples found in repository?
examples/demo.rs (line 141)
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
fn ui(f: &mut ratatui::Frame, app: &mut App) {
    let all_sets = [
        ("ASCII", throbber_widgets_tui::ASCII),
        ("BOX_DRAWING", throbber_widgets_tui::BOX_DRAWING),
        ("ARROW", throbber_widgets_tui::ARROW),
        ("DOUBLE_ARROW", throbber_widgets_tui::DOUBLE_ARROW),
        ("VERTICAL_BLOCK", throbber_widgets_tui::VERTICAL_BLOCK),
        ("HORIZONTAL_BLOCK", throbber_widgets_tui::HORIZONTAL_BLOCK),
        ("QUADRANT_BLOCK", throbber_widgets_tui::QUADRANT_BLOCK),
        (
            "QUADRANT_BLOCK_CRACK",
            throbber_widgets_tui::QUADRANT_BLOCK_CRACK,
        ),
        ("WHITE_SQUARE", throbber_widgets_tui::WHITE_SQUARE),
        ("WHITE_CIRCLE", throbber_widgets_tui::WHITE_CIRCLE),
        ("BLACK_CIRCLE", throbber_widgets_tui::BLACK_CIRCLE),
        ("CLOCK", throbber_widgets_tui::CLOCK),
        ("BRAILLE_ONE", throbber_widgets_tui::BRAILLE_ONE),
        ("BRAILLE_SIX", throbber_widgets_tui::BRAILLE_SIX),
        ("BRAILLE_EIGHT", throbber_widgets_tui::BRAILLE_EIGHT),
        ("BRAILLE_DOUBLE", throbber_widgets_tui::BRAILLE_DOUBLE),
        (
            "BRAILLE_SIX_DOUBLE",
            throbber_widgets_tui::BRAILLE_SIX_DOUBLE,
        ),
        (
            "BRAILLE_EIGHT_DOUBLE",
            throbber_widgets_tui::BRAILLE_EIGHT_DOUBLE,
        ),
        ("OGHAM_A", throbber_widgets_tui::OGHAM_A),
        ("OGHAM_B", throbber_widgets_tui::OGHAM_B),
        ("OGHAM_C", throbber_widgets_tui::OGHAM_C),
        ("PARENTHESIS", throbber_widgets_tui::PARENTHESIS),
        ("CANADIAN", throbber_widgets_tui::CANADIAN),
    ];
    let horizontal_num = 4;
    // why +1? because the first line is for title default throbber.
    let vertical_num = 1 + (all_sets.len() + horizontal_num - 1) / horizontal_num;
    let verticals = ratatui::layout::Layout::default()
        .direction(ratatui::layout::Direction::Vertical)
        .constraints(&vec![ratatui::layout::Constraint::Length(1); vertical_num])
        .split(f.area());
    let default_throbber = throbber_widgets_tui::Throbber::default()
        .label("Press q to exit. This line is a default throbber (random step). The followings are incremental step.")
        .style(ratatui::style::Style::default().fg(ratatui::style::Color::Yellow));
    f.render_widget(default_throbber, verticals[0]);

    let mut chunks: Option<_> = None;
    for (i, kvp) in all_sets.iter().enumerate() {
        let (name, set) = kvp;
        let row = i / horizontal_num;
        let col = i % horizontal_num;
        if col == 0 {
            chunks = Some(
                ratatui::layout::Layout::default()
                    .direction(ratatui::layout::Direction::Horizontal)
                    .constraints(&vec![
                        ratatui::layout::Constraint::Percentage(
                            100 / (horizontal_num as u16)
                        );
                        horizontal_num
                    ])
                    .split(verticals[row + 1]),
            );
        }
        if app.states.len() <= i {
            app.states
                .push(throbber_widgets_tui::ThrobberState::default());
        }
        let throbber = throbber_widgets_tui::Throbber::default()
            .label(name.to_string())
            .throbber_set(set.clone());
        f.render_stateful_widget(throbber, chunks.clone().unwrap()[col], &mut app.states[i]);
    }
}
source

pub fn use_type(self, use_type: WhichUse) -> Self

source

pub fn to_symbol_span(&self, state: &ThrobberState) -> Span<'a>

Convert symbol only to Span with state.

source

pub fn to_line(&self, state: &ThrobberState) -> Line<'a>

Convert symbol and label to Line with state.

Trait Implementations§

source§

impl<'a> Clone for Throbber<'a>

source§

fn clone(&self) -> Throbber<'a>

Returns a copy 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<'a> Debug for Throbber<'a>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a> Default for Throbber<'a>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a> From<Throbber<'a>> for Line<'a>

Convert symbol and label to Line without state(mostly random index).

If you want to specify a state, use Throbber::to_line().

source§

fn from(throbber: Throbber<'a>) -> Line<'a>

Converts to this type from the input type.
source§

impl<'a> From<Throbber<'a>> for Span<'a>

Convert symbol only to Span without state(mostly random index).

If you want to specify a state, use Throbber::to_symbol_span().

source§

fn from(throbber: Throbber<'a>) -> Span<'a>

Converts to this type from the input type.
source§

impl<'a> StatefulWidget for Throbber<'a>

source§

fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State)

Render specified index symbols.

§

type State = ThrobberState

State associated with the stateful widget. Read more
source§

impl<'a> Widget for Throbber<'a>

source§

fn render(self, area: Rect, buf: &mut Buffer)

Render random step symbols.

Auto Trait Implementations§

§

impl<'a> Freeze for Throbber<'a>

§

impl<'a> RefUnwindSafe for Throbber<'a>

§

impl<'a> Send for Throbber<'a>

§

impl<'a> Sync for Throbber<'a>

§

impl<'a> Unpin for Throbber<'a>

§

impl<'a> UnwindSafe for Throbber<'a>

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

§

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>,

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V