Print time more logically
[dnsseed-rust] / src / printer.rs
index 4818d9af61ce4076dddc53de9a349e7cc3051c9f..0d928b0328b1fa21f46621d8c216ccd3a9d5475d 100644 (file)
@@ -50,28 +50,11 @@ impl Printer {
                                }
 
                                out.write_all(b"\nNode counts by status:\n").expect("stdout broken?");
-                               out.write_all(format!("Untested:               {}\n", store.get_node_count(AddressState::Untested)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Low Block Count:        {}\n", store.get_node_count(AddressState::LowBlockCount)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("High Block Count:       {}\n", store.get_node_count(AddressState::HighBlockCount)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Low Version:            {}\n", store.get_node_count(AddressState::LowVersion)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Bad Version:            {}\n", store.get_node_count(AddressState::BadVersion)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Not Full Node:          {}\n", store.get_node_count(AddressState::NotFullNode)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Protocol Violation:     {}\n", store.get_node_count(AddressState::ProtocolViolation)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Timeout:                {}\n", store.get_node_count(AddressState::Timeout)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Timeout During Request: {}\n", store.get_node_count(AddressState::TimeoutDuringRequest)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Good:                   {}\n", store.get_node_count(AddressState::Good)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("WasGood:                {}\n", store.get_node_count(AddressState::WasGood)
-                                               ).as_bytes()).expect("stdout broken?");
+                               for i in 0..AddressState::get_count() {
+                                       out.write_all(format!("{:22}: {}\n", AddressState::from_num(i).unwrap().to_str(),
+                                                       store.get_node_count(AddressState::from_num(i).unwrap())
+                                                       ).as_bytes()).expect("stdout broken?");
+                               }
 
                                out.write_all(format!(
                                                "\nCurrent connections open/in progress: {}\n", stats.connection_count).as_bytes()).expect("stdout broken?");
@@ -92,39 +75,13 @@ impl Printer {
                                                ).as_bytes()).expect("stdout broken?");
 
                                out.write_all(b"\nRetry times (in seconds):\n").expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Untested:               {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::Untested))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Low Block Count:        {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::LowBlockCount))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "High Block Count        {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::HighBlockCount))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Low Version:            {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::LowVersion))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Bad Version:            {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::BadVersion))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Not Full Node:          {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::NotFullNode))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Protocol Violation:     {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::ProtocolViolation))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Timeout:                {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::Timeout))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Timeout During Request: {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::TimeoutDuringRequest))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Good:                   {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::Good))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Was Good:               {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::WasGood))
-                                               ).as_bytes()).expect("stdout broken?");
+                               for i in 0..AddressState::get_count() {
+                                       let scan_secs = store.get_u64(U64Setting::RescanInterval(AddressState::from_num(i).unwrap()));
+                                       out.write_all(format!(
+                                                       "{:22} ({:2}): {:5} (ie {} hrs, {} min)\n", AddressState::from_num(i).unwrap().to_str(), i,
+                                                       scan_secs, scan_secs / 60 / 60, (scan_secs / 60) % 60,
+                                                       ).as_bytes()).expect("stdout broken?");
+                               }
 
                                out.write_all(b"\nCommands:\n").expect("stdout broken?");
                                out.write_all(b"q: quit\n").expect("stdout broken?");
@@ -149,9 +106,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();
                }