Explorar o código

Added colors.

Eiyeron Fulmincendii %!s(int64=8) %!d(string=hai) anos
pai
achega
ba014e5afe
Modificáronse 1 ficheiros con 6 adicións e 5 borrados
  1. 6 5
      src/main.rs

+ 6 - 5
src/main.rs

@@ -4,6 +4,7 @@ extern crate systemstat;
 
 use std::thread;
 use termion::{cursor, color, clear, terminal_size};
+use termion::color::Color;
 use termion::raw::{IntoRawMode, RawTerminal};
 use termion::screen::{AlternateScreen};
 use termion::async_stdin;
@@ -40,10 +41,10 @@ fn print_mem_load<W:Write>(stdout:&mut W, memory:Memory)
     ).unwrap();
 }
 
-fn print_graph<W:Write>(stdout:&mut W, values:&[f32], y_pos:u16)
+fn print_graph<W:Write, C:Color>(stdout:&mut W, values:&[f32], y_pos:u16, color:color::Fg<C>)
 {
     const GRAPH:&'static str = "▁▂▃▄▅▆▇█";
-    write!(stdout, "{}{}{}", cursor::Goto(1, y_pos), clear::CurrentLine, color::Fg(color::White)).unwrap();
+    write!(stdout, "{}{}{}", cursor::Goto(1, y_pos), clear::CurrentLine, color).unwrap();
     for value in values {
         if *value <= 1. as f32
         {
@@ -57,7 +58,7 @@ fn print_graph<W:Write>(stdout:&mut W, values:&[f32], y_pos:u16)
         }
         else
         {
-            write!(stdout, "{}█{}", color::Fg(color::Red), color::Fg(color::White)).unwrap();
+            write!(stdout, "{}█{}", color::Fg(color::Red), color).unwrap();
 
         }
     }
@@ -104,8 +105,8 @@ fn main() {
                         print_mem_load(&mut screen, mem_load);
                     }
 
-                    print_graph(&mut screen, &cpu_load_graph[0..min(x, cpu_load_graph.len())], 1);
-                    print_graph(&mut screen, &mem_load_graph[0..min(x, mem_load_graph.len())], 2);
+                    print_graph(&mut screen, &cpu_load_graph[0..min(x, cpu_load_graph.len())], 1, color::Fg(color::White));
+                    print_graph(&mut screen, &mem_load_graph[0..min(x, mem_load_graph.len())], 2, color::Fg(color::Blue));
 
                     screen.flush().unwrap();
                     num_seconds = new_time;