throbber_widgets_tui/lib.rs
1/*!
2# Throbber widget of [ratatui]
3
4[ratatui]: https://github.com/ratatui-org/ratatui
5[tui-rs]: https://github.com/fdehau/tui-rs
6
7> **_NOTE:_** If you want to use [tui-rs] instead of [ratatui], please use 0.4.1 or older version.
8
9`throbber-widgets-tui` is a [ratatui] widget that displays throbber.
10
11A throbber may also be called:
12
13- activity indicator
14- indeterminate progress bar
15- loading icon
16- spinner
17- guru guru
18
19## Demo
20
21
22
23The demo shown in the gif can be run with all available symbols.
24
25```sh
26cargo run --example demo --release
27```
28
29## Features
30
31- Render throbber
32- With label
33- Random or specified step, also negative is possible.
34
35## Getting Started
36
37MSRV: `throbber-widgets-tui` requires rustc 1.74.0 or newer.
38
39```sh
40cargo add throbber-widgets-tui
41```
42
43Example code:
44
45```rust
46// :
47// :
48struct App {
49 throbber_state: throbber_widgets_tui::ThrobberState,
50}
51impl App {
52 fn on_tick(&mut self) {
53 self.throbber_state.calc_next();
54 }
55}
56// :
57// :
58fn ui(f: &mut ratatui::Frame, app: &mut App) {
59 let chunks = ratatui::layout::Layout::default()
60 .direction(ratatui::layout::Direction::Horizontal)
61 .margin(1)
62 .constraints(
63 [
64 ratatui::layout::Constraint::Percentage(50),
65 ratatui::layout::Constraint::Percentage(50),
66 ]
67 .as_ref(),
68 )
69 .split(f.area());
70
71 // Simple random step
72 let simple = throbber_widgets_tui::Throbber::default();
73 f.render_widget(simple, chunks[0]);
74
75 // Set full with state
76 let full = throbber_widgets_tui::Throbber::default()
77 .label("Running...")
78 .style(ratatui::style::Style::default().fg(ratatui::style::Color::Cyan))
79 .throbber_style(ratatui::style::Style::default().fg(ratatui::style::Color::Red).add_modifier(ratatui::style::Modifier::BOLD))
80 .throbber_set(throbber_widgets_tui::CLOCK)
81 .use_type(throbber_widgets_tui::WhichUse::Spin);
82 f.render_stateful_widget(full, chunks[1], &mut app.throbber_state);
83}
84```
85
86## Apps using throbber-widgets-tui
87
88- [mntime](https://github.com/arkbig/mntime): Execute "m" commands "n" times to calculate mean of usage time and memory. As an alternative to "time", "gnu-time" is used internally.
89
90## Dependencies (By default)
91
92Direct dependencies crates:
93
94|License|crate|
95|-|-|
96|Apache-2.0 OR MIT (1)| rand|
97|MIT (1)| ratatui|
98|Zlib (1)| throbber-widgets-tui|
99
100Chain dependencies crates:
101
102|License|crate|
103|-|-|
104|(MIT OR Apache-2.0) AND Unicode-DFS-2016 (1)| unicode-ident|
105|Apache-2.0 OR Apache-2.0 WITH LLVM-exception OR MIT (3)| linux-raw-sys, rustix, wasi|
106|Apache-2.0 OR BSD-2-Clause OR MIT (2)| zerocopy, zerocopy-derive|
107|Apache-2.0 OR BSL-1.0 (1)| ryu|
108|Apache-2.0 OR MIT (51)| allocator-api2, bitflags, cassowary, cfg-if, either, equivalent, errno, getrandom, hashbrown, heck, hermit-abi, indoc, itertools, itoa, libc, lock_api, log, 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, unicode-segmentation, unicode-truncate, unicode-width, 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_gnullvm, windows_i686_msvc, windows_x86_64_gnu, windows_x86_64_gnullvm, windows_x86_64_msvc|
109|MIT (11)| castaway, compact_str, crossterm, crossterm_winapi, instability, lru, mio, ratatui, redox_syscall, strum, strum_macros|
110|MIT OR Unlicense (1)| byteorder|
111|Zlib (2)| foldhash, throbber-widgets-tui|
112
113## License
114
115This repository's license is zlib. Please feel free to use this, but no warranty.
116*/
117
118pub mod symbols;
119pub mod widgets;
120
121pub use self::symbols::throbber::*;
122pub use self::widgets::*;