[chg] logtimes initial version

This commit is contained in:
2020-07-30 10:15:18 +02:00
commit 606d882ec1
4 changed files with 155 additions and 0 deletions

49
src/main.rs Normal file
View File

@ -0,0 +1,49 @@
use std::io::{Write, Read, ErrorKind, stdin, stdout};
use chrono::prelude::*;
#[inline(always)]
fn print_time() {
let date_now = Local::now().format("%H:%M:%S%.9f");
let color_green = "\x1b\x5b\x30\x3b\x33\x32\x6d";
let color_off = "\x1b\x5b\x30\x6d";
print!("{}[{}]{} ", color_green, &date_now, color_off);
}
fn main() {
let out = stdout();
let mut output = out.lock();
let inp = stdin();
let mut input = inp.lock();
print_time();
loop {
let mut buf = [0; 1];
let _ = input.read_exact(&mut buf).map_err(|e| {
if e.kind() != ErrorKind::UnexpectedEof {
println!("{}", e.to_string());
std::process::exit(1);
}
let _ = output.flush();
std::process::exit(0);
});
if buf[0] == 0xa {
print!("\n");
print_time();
continue;
}
let _ = output.write_all(&mut buf);
let _ = output.flush();
}
}