diff options
-rw-r--r-- | Cargo.lock | 76 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | output.gif | bin | 15847236 -> 17824097 bytes | |||
-rw-r--r-- | src/main.rs | 21 |
4 files changed, 95 insertions, 3 deletions
@@ -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]] @@ -138,12 +139,28 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -234,6 +251,24 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -260,6 +295,31 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -291,6 +351,12 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" @@ -300,6 +366,12 @@ dependencies = [ ] [[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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -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]] @@ -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" Binary files differdiff --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!("="); } } |