#tui #widgets

throbber-widgets-tui

This is a ratatui (or tui-rs) widget that displays throbber

7 unstable releases (3 breaking)

new 0.4.0 Feb 13, 2024
0.3.0 Nov 1, 2023
0.2.0 Aug 27, 2023
0.1.3 Nov 9, 2022
0.1.2 Oct 12, 2022

#1566 in Command line utilities

Download history 46/week @ 2023-10-26 42/week @ 2023-11-02 19/week @ 2023-11-09 24/week @ 2023-11-16 27/week @ 2023-11-23 28/week @ 2023-11-30 34/week @ 2023-12-07 28/week @ 2023-12-14 40/week @ 2023-12-21 9/week @ 2023-12-28 18/week @ 2024-01-04 21/week @ 2024-01-11 17/week @ 2024-01-18 19/week @ 2024-01-25 28/week @ 2024-02-01 63/week @ 2024-02-08

129 downloads per month
Used in mntime

Zlib license

86KB
318 lines

Throbber widget of ratatui

NOTE: This crate was originally created as a widget for tui-rs, so you can see tui:: on the sample code, but (by default) ratatui is used, so please replace it accordingly.

throbber-widgets-tui is a ratatui (or tui-rs) widget that displays throbber.

A throbber may also be called:

  • activity indicator
  • indeterminate progress bar
  • loading icon
  • spinner
  • ぐるぐる(guru guru)

Demo

Demo Animation

The demo shown in the gif can be run with all available symbols.

cargo run --example demo --release

Features

  • Render throbber
  • With label
  • Random or specified step, also negative is possible.

Getting Started

MSRV: throbber-widgets-tui requires rustc 1.72.0 or newer.

cargo add throbber-widgets-tui

Default is ratatui as tui.

OR use [tui-rs] instead of [ratatui]. use `tui` features like clicked here.
cargo add throbber-widgets-tui --no-default-features --features tui

Example code:

#[cfg(feature = "ratatui")]
use ratatui as tui;
// :
// :
struct App {
    throbber_state: throbber_widgets_tui::ThrobberState,
}
impl App {
    fn on_tick(&mut self) {
        self.throbber_state.calc_next();
    }
}
// :
// :
// If use tui-rs or ratatui v0.23.0 or older, use bellow.
//fn ui<B: tui::backend::Backend>(f: &mut tui::Frame<B>, app: &mut App) {
#[cfg(feature = "ratatui")]
fn ui(f: &mut tui::Frame, app: &mut App) {
    let chunks = tui::layout::Layout::default()
        .direction(tui::layout::Direction::Horizontal)
        .margin(1)
        .constraints(
            [
                tui::layout::Constraint::Percentage(50),
                tui::layout::Constraint::Percentage(50),
            ]
            .as_ref(),
        )
        .split(f.size());

    // Simple random step
    let simple = throbber_widgets_tui::Throbber::default();
    f.render_widget(simple, chunks[0]);

    // Set full with state
    let full = throbber_widgets_tui::Throbber::default()
        .label("Running...")
        .style(tui::style::Style::default().fg(tui::style::Color::Cyan))
        .throbber_style(tui::style::Style::default().fg(tui::style::Color::Red).add_modifier(tui::style::Modifier::BOLD))
        .throbber_set(throbber_widgets_tui::CLOCK)
        .use_type(throbber_widgets_tui::WhichUse::Spin);
    f.render_stateful_widget(full, chunks[1], &mut app.throbber_state);
}

Apps using throbber-widgets-tui

  • mntime: Execute "m" commands "n" times to calculate mean of usage time and memory. As an alternative to "time", "gnu-time" is used internally.

Dependencies (By default)

Direct dependencies crates:

cargo license --direct-deps-only --avoid-build-deps --avoid-dev-deps | awk -F ":" 'BEGIN {printf "|License|crate|\n|-|-|\n"} {printf "|%s|%s|\n", $1, $2}'
License crate
Apache-2.0 OR MIT (1) rand
MIT (2) crossterm, ratatui
Zlib (1) throbber-widgets-tui

Chain dependencies crates:

cargo license --avoid-build-deps --avoid-dev-deps | awk -F ":" 'BEGIN {printf "|License|crate|\n|-|-|\n"} {printf "|%s|%s|\n", $1, $2}'
License crate
(MIT OR Apache-2.0) AND Unicode-DFS-2016 (1) unicode-ident
Apache-2.0 OR Apache-2.0 WITH LLVM-exception OR MIT (1) wasi
Apache-2.0 OR BSD-2-Clause OR MIT (2) zerocopy, zerocopy-derive
Apache-2.0 OR BSL-1.0 (1) ryu
Apache-2.0 OR MIT (49) ahash, allocator-api2, bitflags, bitflags, cassowary, cfg-if, either, getrandom, hashbrown, heck, indoc, itertools, itoa, libc, lock_api, log, once_cell, parking_lot, parking_lot_core, paste, ppv-lite86, proc-macro2, quote, rand, rand_chacha, rand_core, rustversion, scopeguard, signal-hook, signal-hook-mio, signal-hook-registry, smallvec, static_assertions, syn, syn, unicode-segmentation, unicode-width, winapi, winapi-i686-pc-windows-gnu, winapi-x86_64-pc-windows-gnu, windows-sys, windows-targets, windows_aarch64_gnullvm, windows_aarch64_msvc, windows_i686_gnu, windows_i686_msvc, windows_x86_64_gnu, windows_x86_64_gnullvm, windows_x86_64_msvc
MIT (11) castaway, compact_str, crossterm, crossterm_winapi, lru, mio, ratatui, redox_syscall, stability, strum, strum_macros
Zlib (1) throbber-widgets-tui

License

This repository's license is zlib. Please feel free to use this, but no warranty.

Dependencies

~6–16MB
~174K SLoC