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>
impl<'a> Throbber<'a>
sourcepub fn label<T>(self, label: T) -> Self
pub fn label<T>(self, label: T) -> Self
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]);
}
}
sourcepub fn style(self, style: Style) -> Self
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]);
}
}
pub fn throbber_style(self, style: Style) -> Self
sourcepub fn throbber_set(self, set: Set) -> Self
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]);
}
}
pub fn use_type(self, use_type: WhichUse) -> Self
sourcepub fn to_symbol_span(&self, state: &ThrobberState) -> Span<'a>
pub fn to_symbol_span(&self, state: &ThrobberState) -> Span<'a>
Convert symbol only to Span with state.
sourcepub fn to_line(&self, state: &ThrobberState) -> Line<'a>
pub fn to_line(&self, state: &ThrobberState) -> Line<'a>
Convert symbol and label to Line with state.
Trait Implementations§
source§impl<'a> From<Throbber<'a>> for Line<'a>
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§impl<'a> From<Throbber<'a>> for Span<'a>
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§impl<'a> StatefulWidget for Throbber<'a>
impl<'a> StatefulWidget for Throbber<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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