From e8e391abb2789034138b430e6e129a20f6aa6d1a Mon Sep 17 00:00:00 2001 From: jacob janzen Date: Sun, 28 Aug 2022 11:56:44 -0500 Subject: added progress bar --- Cargo.lock | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 1 + output.gif | Bin 15847236 -> 17824097 bytes src/main.rs | 21 ++++++++++++++++- 4 files changed, 95 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 15175af..db7af99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -32,6 +32,7 @@ dependencies = [ "clap", "gif", "rand", + "termsize", ] [[package]] @@ -137,12 +138,28 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + [[package]] name = "libc" version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" + [[package]] name = "once_cell" version = "1.13.1" @@ -233,6 +250,24 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_termios" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" +dependencies = [ + "redox_syscall", +] + [[package]] name = "strsim" version = "0.10.0" @@ -259,6 +294,31 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termion" +version = "1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" +dependencies = [ + "libc", + "numtoa", + "redox_syscall", + "redox_termios", +] + +[[package]] +name = "termsize" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e86d824a8e90f342ad3ef4bd51ef7119a9b681b0cc9f8ee7b2852f02ccd2517" +dependencies = [ + "atty", + "kernel32-sys", + "libc", + "termion", + "winapi 0.2.8", +] + [[package]] name = "textwrap" version = "0.15.0" @@ -289,6 +349,12 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -299,6 +365,12 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -311,7 +383,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index eba99ab..adb4781 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ keywords = ["generative-art","gif"] gif = "0.11.4" rand = "0.8.5" clap = { version = "3.2.17", features = ["derive"]} +termsize = "0.1.6" diff --git a/output.gif b/output.gif index 00beb0a..f2c0388 100644 Binary files a/output.gif and b/output.gif differ diff --git a/src/main.rs b/src/main.rs index faff0eb..b904808 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,12 +14,16 @@ */ use std::fs::File; use std::process; +use std::sync::mpsc; +use std::thread; use bubbles::Args; use bubbles::Image; fn main() { let args = Args::read(); + let (tx, rx) = mpsc::channel(); + let width = termsize::get().unwrap().cols; // create Gif data let mut data = Image::create_from_args(&args); @@ -33,13 +37,28 @@ fn main() { process::exit(1); } + thread::spawn(move || { + for received in rx { + let percent_done = received as f64 / data.frames as f64; + + for i in 0..(width as i32 - 5) as i32 { + if i < (percent_done * width as f64) as i32 { + print!("="); + } else { + print!("-"); + } + } + print!("[{}%]\r", (percent_done * 100.0) as i32); + } + }); + for i in 0..data.frames { + tx.send(i).unwrap(); // Create pixel array data.fill_canvas(i); let frame = gif::Frame::from_rgb(data.width, data.height, &mut data.pixels); // Write frame to file encoder.write_frame(&frame).unwrap(); - print!("="); } } -- cgit v1.2.3