Skip to content

Instantly share code, notes, and snippets.

@obvionaoe
Created June 23, 2020 02:09
Show Gist options
  • Save obvionaoe/cadf03d5bd63e1a9d852d3a9174e9247 to your computer and use it in GitHub Desktop.
Save obvionaoe/cadf03d5bd63e1a9d852d3a9174e9247 to your computer and use it in GitHub Desktop.
A simple loading bar written in Rust
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