-
-
Notifications
You must be signed in to change notification settings - Fork 134
Open
Description
Description:
While a progress bar from the console crate is running, pressing Ctrl + C interrupts the program but leaves the terminal cursor hidden. The cursor is not restored automatically, so the terminal stays in a broken state until manually reset.
This is the sample code i am testing
use console::Term;
use std::thread;
use std::time::Duration;
fn main() -> std::io::Result<()> {
let term = Term::stderr();
term.hide_cursor()?;
let mut last_lines = 0usize;
let mut a = 0;
let mut b = 0;
loop {
let bar1 = format!("Download A: [{}{}] {}%", "#".repeat(a), " ".repeat(20 - a), a * 5);
let bar2 = format!("Download B: [{}{}] {}%", "#".repeat(b), " ".repeat(20 - b), b * 5);
let frame = vec![bar1, bar2];
if last_lines > 0 {
term.move_cursor_up(last_lines)?;
}
for line in &frame {
term.clear_line()?;
term.write_line(line)?;
}
term.flush()?;
last_lines = frame.len();
if a < 20 { a += 1; }
if b < 20 { b += 1; }
if a == 20 && b == 20 {
break;
}
thread::sleep(Duration::from_millis(200));
}
term.show_cursor()?;
Ok(())
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels