https://github.com/mutokrm/cli_animate
Enrich your Rust CLIs with stunning, easy-to-implement animations. Thanks for over 1,000 downloads!
https://github.com/mutokrm/cli_animate
animation cli cli-interface progress-bar rust
Last synced: 8 days ago
JSON representation
Enrich your Rust CLIs with stunning, easy-to-implement animations. Thanks for over 1,000 downloads!
- Host: GitHub
- URL: https://github.com/mutokrm/cli_animate
- Owner: mutokrm
- License: mit
- Created: 2023-10-22T08:52:19.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-24T14:03:22.000Z (about 2 years ago)
- Last Synced: 2025-03-02T06:28:04.202Z (10 months ago)
- Topics: animation, cli, cli-interface, progress-bar, rust
- Language: Rust
- Homepage: https://crates.io/crates/cli-animate
- Size: 75.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cli-animate
`cli-animate` is a Rust crate designed to **enrich command-line applications with a variety of beautiful, easy-to-use animations**.
It offers a straightforward way to integrate visual elements such as progress bars, interactive menus, and more, enhancing the interactivity of your CLIs.
## Features
**Progress Bars**: Show task progress with customizable, animated progress bars. \
**Interactive Menus**: Navigate through options with intuitive, keyboard-navigable menus. \
**Loading Indicators**: Display a loading indicator to show that your application is working. \
**Styles Customizable**: Customize the look of your animations with colors and characters. \
**And More**: The library is designed for extensibility and includes a variety of other tools to enrich your CLI applications.
## Installation
Add `cli-animate` to your `Cargo.toml` file's dependencies section:
```
[dependencies]
cli-animate = "0.1.0"
```
## Example
**Interactive Menu**:

```rust
use cli_animate::InteractiveMenu;
fn main() {
let options = vec![
"Tokyo".to_string(),
"Saitama".to_string(),
"Kanagawa".to_string(),
];
let mut menu = InteractiveMenu::new(options.clone());
// Run it!
let selected_index = menu.run().unwrap(); // Returns the index of the user's selected option.
println!("You selected: {}", options[selected_index]); // "You selected: Tokyo"
}
```
**Progress Bar**:

```rust
use cli_animate::{ProgressBar, StyleBuilder, Color};
fn main() {
let progress_value = Arc::new(Mutex::new(0));
// Create a clone of the progress_value for the other thread.
let thread_progress_value = progress_value.clone();
// Some work done in another thread.
let do_some_work = thread::spawn(move || {
let mut num = 0;
while num <= 100 {
thread::sleep(time::Duration::from_millis(20));
let mut val = thread_progress_value.lock().unwrap(); // Update the progress value.
*val = num;
num += 1;
}
});
// Initialize a progress bar.
let style = StyleBuilder::new() // Customize the progress bar's style!
.color(Color::Green)
.bar_length(20)
.build();
let progress_bar = ProgressBar::new(0, 100, move || *progress_value.lock().unwrap(), style);
let mut writer = std::io::stdout();
// Start it!
progress_bar.start(&mut writer);
// Wait for the worker thread to finish.
do_some_work.join().unwrap();
}
```
Check out the `examples/` directory in the repository for more usage examples of cli-animate.
## License
This project is licensed under the MIT License - see the LICENSE file for details.
Thank you for using `cli-animate` to make your command-line applications more attractive and engaging!