Skip to content

Commit

Permalink
feat: Added more features to progbar (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan26 authored Sep 30, 2024
2 parents 3ca664b + 3db0942 commit aa93628
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 56 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zung"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
authors = ["Ishaan Goel <[email protected]>"]
description = "A monolith of rust projects"
Expand All @@ -14,6 +14,6 @@ members = ["zung_mini"]
resolver = "2"

[dependencies]
zung_mini = "0.1.2"
zung_mini = { version = "0.2.0", path = "./zung_mini" }
anstyle = "1.0.8"
clap = { version = "4.5.18", features = ["derive"] }
2 changes: 1 addition & 1 deletion zung_mini/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zung_mini"
version = "0.1.2"
version = "0.2.0"
edition = "2021"
authors = ["Ishaan Goel <[email protected]>"]
description = "Mini rust projects that target specific features of rust"
Expand Down
26 changes: 26 additions & 0 deletions zung_mini/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
Mini rust projects that target specific features of rust

> # Disclaimer
> This library is intended for **learning purposes only** and is not production-grade. While it demonstrates core functionality for implementing a progress bar in Rust, it may lack the optimizations, testing, and features required for production use. Use at your own risk in critical applications.
## Table of Contents

- [Mini Project 1](#mini-project-1---progbar)
- [Usage](#usage)

# Mini Project 1 - ProgBar

> A Simple Progress Bar for Rust Iterators
`ProgBar` is a lightweight and customizable progress bar library for Rust iterators. It allows you to easily track the progress of any iterator in your terminal with visual feedback. Whether your iterator is bounded (has a known size) or unbounded, `ProgBar` adapts to display the progress accordingly.

## Features

- **Simple Integration**: Easily add progress bars to any iterator with minimal code changes.
- **Supports Bounded & Unbounded Iterators**: Progress can be tracked for both finite and infinite iterators.
- **Customizable Appearance**: Modify the style and delimiters of the progress bar.
- **Real-time Terminal Display**: Live updates of the progress bar in the terminal as your iterator progresses.

## Usage

See the [docs](https://docs.rs/zung_mini/0.1.2/zung_mini/progbar/index.html) for how to use this library.
60 changes: 47 additions & 13 deletions zung_mini/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub mod progbar;
use clap::{Args, Subcommand};
use progbar::ProgBarExt;

/// An example Clap Argument builder. Install the [`zung`](https://crates.io/crates/zung) crate and
/// run `zung mini progbar` to see what options are available
#[derive(Debug, Args)]
#[command(flatten_help = true, subcommand_required = true)]
pub struct MiniArgs {
Expand All @@ -19,6 +21,28 @@ pub struct MiniArgs {
enum MiniCommands {
/// Print a progress bar to an iterator.
Progbar {
#[command(subcommand)]
command: ProgBarCommands,
},
}

#[derive(Clone, Subcommand, Debug)]
#[command(arg_required_else_help = true)]
enum ProgBarCommands {
UnBounded {
#[arg(short, long, default_value_t = String::from("Simulating Loading..."))]
message: String,
},
Bounded {
#[arg(long, default_value_t = String::from("["))]
delim_start: String,

#[arg( long, default_value_t = String::from("]"))]
delim_close: String,

#[arg(long, default_value_t = String::from("#"))]
bar_style: String,

#[arg(short, long, default_value_t = 50)]
iter_count: u8,
},
Expand All @@ -27,22 +51,32 @@ enum MiniCommands {
impl MiniArgs {
pub fn run(self) {
match self.command {
MiniCommands::Progbar { iter_count } => {
MiniCommands::Progbar { command } => {
use std::thread::sleep;
use std::time::Duration;

// test run UnBounded
for _ in (0..iter_count).progbar() {
sleep(Duration::from_millis(50))
}

// test run Bounded
for _ in (0..iter_count)
.progbar()
.bar_style('=')
.with_bounds('(', ')')
{
sleep(Duration::from_millis(50))
match command {
ProgBarCommands::UnBounded { message } => {
// test run UnBounded
for _ in (0..).progbar().with_message(&message) {
sleep(Duration::from_millis(50))
}
}
ProgBarCommands::Bounded {
delim_start,
delim_close,
bar_style,
iter_count,
} => {
// test run Bounded
for _ in (0..iter_count)
.progbar()
.with_bounds(delim_start, delim_close)
.bar_style(bar_style)
{
sleep(Duration::from_millis(50))
}
}
}
}
}
Expand Down
Loading

0 comments on commit aa93628

Please sign in to comment.