-
Rust연습❤️Processing 0~100%올라가는 프린트 ㅎㅎ코딩Coding/Rust연습 2022. 8. 13. 23:23728x90
use std::{ io::{stdout, Write}, thread::sleep, time::Duration, }; fn main() { let mut stdout = stdout(); for i in 0..=100 { print!("\rProcessing {}%...", i); // or // stdout.write(format!("\rProcessing {}%...", i).as_bytes()).unwrap(); stdout.flush().unwrap(); sleep(Duration::from_millis(20)); } println!(); }
cargo run Compiling char v0.1.0 (/Users/globalyoung/Documents/test/rust/char) Finished dev [unoptimized + debuginfo] target(s) in 2.16s Running `target/debug/char` Processing 100%...
https://stackoverflow.com/questions/59890270/how-do-i-overwrite-console-output
30에서 부터 0으로 줄어듬
use crossterm::{cursor, terminal, ExecutableCommand, QueueableCommand}; use std::io::{stdout, Write}; use std::{thread, time}; fn main() { let mut stdout = stdout(); stdout.execute(cursor::Hide).unwrap(); for i in (1..30).rev() { stdout.queue(cursor::SavePosition).unwrap(); stdout .write_all(format!("{}: FOOBAR ", i).as_bytes()) .unwrap(); stdout.queue(cursor::RestorePosition).unwrap(); stdout.flush().unwrap(); thread::sleep(time::Duration::from_millis(100)); stdout.queue(cursor::RestorePosition).unwrap(); stdout .queue(terminal::Clear(terminal::ClearType::FromCursorDown)) .unwrap(); } stdout.execute(cursor::Show).unwrap(); println!("Done!"); }
Done!
반응형'코딩Coding > Rust연습' 카테고리의 다른 글
Rust연습❤️물어보고 출력 무한 loop (0) 2022.08.14 Rust Machine learning code 불완전함 (0) 2022.08.13 러스트연습❤️ 뭔가 제자리에서 출력되는거 (0) 2022.08.13 Rust연습❤️“rust spinning rod animation in text” Code Answer (0) 2022.08.13 Rust연습❤️HashMap, Arc, Mutex, thread연습 (0) 2022.08.13 Rust연습❤️] Hello from asm__assembly코드 연습 (0) 2022.07.03 Rust연습❤️] Displaying raw pointers (0) 2022.07.03 Rust연습❤️내 컴퓨터에 병렬 실행 가능한 코어수 알아보기available_parallelism (0) 2022.06.29