Created
June 23, 2020 02:09
-
-
Save obvionaoe/cadf03d5bd63e1a9d852d3a9174e9247 to your computer and use it in GitHub Desktop.
A simple loading bar written in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{stdout, Write}; | |
use std::thread::sleep; | |
use std::time::Duration; | |
fn main() { | |
let mut i: u32 = 0; | |
while i <= 100 { | |
print!("\r"); | |
print!("{{"); | |
for _ in 0..i { | |
print!("#") | |
} | |
for _ in 0..(100 - i) { | |
print!(" ") | |
} | |
print!("}} "); | |
print!("{}%", i); | |
sleep(Duration::from_secs(1)); | |
i += 1; | |
stdout().flush().unwrap() | |
} | |
println!(); | |
println!("Finished!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment