Skip to content

Commit

Permalink
feat: Add clear method to MultiSpinner fix #35 (#36)
Browse files Browse the repository at this point in the history
* feat: Add clear method to MultiSpinner/Progressbar

* fmt: fixed formating

* test: fixed failing doc test on input example

* doc: fixed some docs, moved previews down added toc (readme)
  • Loading branch information
Arteiii authored Jun 28, 2024
1 parent 5dd98db commit 99773cc
Show file tree
Hide file tree
Showing 9 changed files with 817 additions and 714 deletions.
37 changes: 26 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!--suppress HtmlDeprecatedAttribute -->
<div align="center">
<img src="images/ZENITY.svg" alt="Zenity svg logo" width="400">
<img src="images/ZENITY.svg" alt="Zenity svg logo" width="400" >
<p>Yet Another Spinner Lib</p>
<p style="margin-top: -10px;">Upgrade your Rust CLIs with 100+ spinner animations, progress bars, and multiline support, plus user input validation, logging, and automatic requirement checks</p>
<a href="https://github.com/Arteiii/zenity/actions/workflows/publish_crate.yml">
Expand All @@ -17,17 +18,24 @@
<a href="https://codecov.io/gh/Arteiii/zenity" >
<img src="https://codecov.io/gh/Arteiii/zenity/graph/badge.svg?token=CHEG2ZD0LW" alt="codecov badge"/>
</a>
<br>
<br>
</div>
<br>

<div align="center">
<img src="images/rustrover64_WupAJU44Lu.gif" alt="progress bar">
</div>
## Table of Contents

![menu input preview](images/rustrover64_Qgn5icero6.gif)
- [Overview](#overview)
- [How to Use?](#how-to-use)
- [Documentation](#documentation)
- [Examples](#examples)
- [Contributing](#contributing)
- [Preview](#preview)
- [Disclaimer](#disclaimer)
- [Credits](#credits)
- [License](#license)

![multiline preview](images/rustrover64_4bzlv2mWxK.gif)

## Overview
Do you often find yourself gazing into the void of your terminal,
wondering if your computer has decided to take a coffee break without notifying you?

Expand All @@ -39,7 +47,7 @@ wondering if your computer has decided to take a coffee break without notifying
## How to Use?

It's as easy as pie (or maybe even easier, depending on your pie-making skills)!
Follow these simple steps:
Follow these steps:

````shell
cargo add zenity
Expand Down Expand Up @@ -69,9 +77,8 @@ fn main() {

check out the examples for more

**NOTE:**

- the lib already includes checks for `--color` following the conventions
> [!NOTE]
> the lib already includes checks for `--color` following the conventions
by:
[Rain's Rust CLI recommendations](https://rust-cli-recommendations.sunshowers.io/colors.html#general-recommendations)

Expand Down Expand Up @@ -110,6 +117,14 @@ If you find this project helpful or enjoyable, consider giving it a star on [Git

Thank you for your interest and contributions!

## Preview

![progress bar](images/rustrover64_WupAJU44Lu.gif)

![menu input preview](images/rustrover64_Qgn5icero6.gif)

![multiline preview](images/rustrover64_4bzlv2mWxK.gif)

## Disclaimer

Now, we won't promise you that cli_loading_magic will solve all your problems.
Expand Down
111 changes: 54 additions & 57 deletions examples/multi_spinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,69 @@ use zenity::spinner::MultiSpinner;
use zenity::style::{Color, StyledString};

fn main() {
{
let check_mark_text = check_mark_button();
let cross_mark_text = cross_mark();
let check_mark_text = check_mark_button();
let cross_mark_text = cross_mark();

let spinner = MultiSpinner::default();
let spinner1 = spinner.get_last();
let spinner = MultiSpinner::default();
spinner.clear(Some(1));
let spinner1 = spinner.get_last();

// main thread operations
let spinner2 = spinner.add(Frames::wavy());
let spinner3 = spinner.add(Frames::dot_spinner9());
let spinner4 = spinner.add(Frames::dot_spinner8());
// main thread operations
let spinner2 = spinner.add(Frames::wavy());
let spinner3 = spinner.add(Frames::dot_spinner9());
let spinner4 = spinner.add(Frames::dot_spinner8());

spinner.run_all();
spinner.run_all();

sleep(Duration::from_secs(4));
spinner.set_text(&spinner2, "spinner2".to_string());
// stop spinner1
spinner.set_styled_text(
&spinner1,
StyledString::simple("spinner1", Some(Color::Blue), Some(Color::DarkBlue), None),
);
sleep(Duration::from_secs(4));
spinner.set_text(&spinner2, "spinner2".to_string());
// stop spinner1
spinner.set_styled_text(
&spinner1,
StyledString::simple("spinner1", Some(Color::Blue), Some(Color::DarkBlue), None),
);

sleep(Duration::from_secs(2));
sleep(Duration::from_secs(2));

spinner.stop(&spinner2);
spinner.set_styled_text(
&spinner2,
StyledString::simple(
&format!("{} Successfully", &check_mark_text),
Some(Color::Green),
None,
None,
),
);
spinner.stop(&spinner2);
spinner.set_styled_text(
&spinner2,
StyledString::simple(
&format!("{} Successfully", &check_mark_text),
Some(Color::Green),
None,
None,
),
);

sleep(Duration::from_secs(2));
spinner.set_text(&spinner1, "spinner1 stopped".to_string());
spinner.stop(&spinner1);
sleep(Duration::from_secs(2));
spinner.set_text(&spinner1, "spinner1 stopped".to_string());
spinner.stop(&spinner1);

spinner.show_line_number();
spinner.show_line_number();

sleep(Duration::from_secs(9));
spinner.stop(&spinner3);
spinner.stop(&spinner4);
sleep(Duration::from_secs(9));
spinner.stop(&spinner3);
spinner.stop(&spinner4);

spinner.set_styled_text(
&spinner3,
StyledString::simple(
&format!("{} Failed!", &cross_mark_text),
Some(Color::Red),
None,
None,
),
);
spinner.set_styled_text(
&spinner4,
StyledString::simple(
&format!("{} Failed!", &cross_mark_text),
Some(Color::Red),
None,
None,
),
);
spinner.set_styled_text(
&spinner3,
StyledString::simple(
&format!("{} Failed!", &cross_mark_text),
Some(Color::Red),
None,
None,
),
);
spinner.set_styled_text(
&spinner4,
StyledString::simple(
&format!("{} Failed!", &cross_mark_text),
Some(Color::Red),
None,
None,
),
);

sleep(Duration::from_secs(1));
}

sleep(Duration::from_secs(5));
sleep(Duration::from_secs(1));
}
3 changes: 3 additions & 0 deletions images/ZENITY.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! ## How to Use?
//!
//! It's as easy as pie (or maybe even easier, depending on your pie-making skills)!
//! Follow these simple steps:
//! Follow these steps:
//!
//! ## Spinner
//!
Expand Down
12 changes: 6 additions & 6 deletions src/menu/input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Input Validation Widgets
//!
//! **Note:** This module is a work in progress,
//! **Note: ** This module is a work in progress,
//! and breaking changes could be made soon without increasing the major version
//! for different reasons, such as improvements or bug fixes.
//!
Expand All @@ -17,7 +17,7 @@ use std::path::Path;

use crossterm::event::{Event, KeyCode, KeyEvent};
use crossterm::{
cursor, execute, terminal,
cursor, execute,
terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType},
};
use regex::Regex;
Expand Down Expand Up @@ -330,7 +330,7 @@ impl Input {
/// Enables the ability to bypass validation requirements and force input submission.
/// This can be triggered by pressing SHIFT + Enter.
///
/// **Note:**
/// **Note: **
/// - This feature may not work in all terminal environments.
/// Refer to issue [#685](https://github.com/crossterm-rs/crossterm/issues/685) for more information.
///
Expand Down Expand Up @@ -526,7 +526,7 @@ impl Input {
///
/// # Examples
///
/// ```
/// ```ignore
/// use zenity::menu::input::Confirm;
///
/// // Create a new confirmation prompt with a title and a default value of 'yes'
Expand Down Expand Up @@ -572,7 +572,7 @@ impl Confirm {
/// ```
/// use zenity::menu::input::Confirm;
///
/// // Create a new Confirm instance with a title and default value
/// // Create a new Confirmation instance with a title and default value
/// let confirm = Confirm::new("Do you want to proceed?", true);
/// ```
pub fn new(title: &str, default: bool) -> Self {
Expand All @@ -599,7 +599,7 @@ impl Confirm {
/// let confirm = Confirm::new("Do you want to proceed?", true).start();
/// ```
pub fn start(&self) -> bool {
terminal::enable_raw_mode().unwrap();
enable_raw_mode().unwrap();

// render the prompt
execute!(io::stdout(), Print(&self.title)).unwrap();
Expand Down
Loading

0 comments on commit 99773cc

Please sign in to comment.