fixed report update

This commit is contained in:
canep 2022-08-25 18:59:08 +02:00
parent 1b410d97e6
commit 0c293f3bbd
2 changed files with 5 additions and 9 deletions

View file

@ -29,6 +29,7 @@ use std::sync::{Arc, Mutex, Condvar};
use crossterm::{screen::RawScreen, input::{input, InputEvent, KeyEvent}};
use colored;
use colored::Colorize;
use std::time::Duration;
/// This enum represents the sniffing process status.
#[derive(PartialEq, Eq)]
@ -258,8 +259,8 @@ fn set_status_by_key(status_pair: Arc<(Mutex<Status>, Condvar)>) {
InputEvent::Keyboard(KeyEvent::Char('p')) => {
if *status == Status::Running {
println!("\t{}", "Sniffnet paused...\r".yellow().bold());
print!("\t{}", "Press 'r' to resume\r".yellow().blink().bold());
io::stdout().flush().unwrap();
print!("\t{}", "Press 'r' to resume\r\n".yellow().blink().bold());
//io::stdout().flush().unwrap();
*status = Status::Pause;
}
}

View file

@ -63,10 +63,6 @@ pub fn sleep_and_write_report_loop(lowest_port: u16, highest_port: u16, interval
loop {
thread::sleep(Duration::from_secs(interval));
let mut _status = status_pair.0.lock().expect("Error acquiring mutex\n\r");
if *_status == Status::Running {
drop(_status);
times_report_updated += 1;
let mut output = File::create(output_file.clone()).expect("Error creating output file\n\r");
@ -89,10 +85,9 @@ pub fn sleep_and_write_report_loop(lowest_port: u16, highest_port: u16, interval
}
println!("{}{}{}\r", "\tReport updated (".cyan().italic(),
times_report_updated.to_string().cyan().italic(), ")".cyan().italic());
}
else {
let mut _status = status_pair.0.lock().expect("Error acquiring mutex\n\r");
_status = cvar.wait_while(_status, |s| *s == Status::Pause).expect("Error acquiring mutex\n\r");
}
}
}