Fix dup block request bug
[dnsseed-rust] / src / printer.rs
index f51fee55bb116b9e49dd9c5b4f9273061b9a291e..37411274ce9181b0bec0196e5f7ae3dc64cd27dd 100644 (file)
@@ -34,14 +34,14 @@ impl Printer {
                std::thread::spawn(move || {
                        loop {
                                std::thread::sleep(std::time::Duration::from_secs(1));
-                               if START_SHUTDOWN.load(Ordering::Relaxed) {
-                                       break;
-                               }
 
                                let stdout = std::io::stdout();
                                let mut out = stdout.lock();
 
                                let stats = thread_arc.lock().unwrap();
+                               if START_SHUTDOWN.load(Ordering::Relaxed) && stats.connection_count == 0 {
+                                       break;
+                               }
 
                                out.write_all(b"\x1b[2J\x1b[;H\n").expect("stdout broken?");
                                for line in stats.lines.iter() {
@@ -149,9 +149,13 @@ impl Printer {
                }
        }
 
-       pub fn add_line(&self, line: String, _err: bool) {
+       pub fn add_line(&self, line: String, err: bool) {
                let mut stats = self.stats.lock().unwrap();
-               stats.lines.push_back(line);
+               if err {
+                       stats.lines.push_back("\x1b[31m".to_string() + &line + "\x1b[0m");
+               } else {
+                       stats.lines.push_back(line);
+               }
                if stats.lines.len() > 50 {
                        stats.lines.pop_front();
                }