diff --git a/src/main.rs b/src/main.rs index 47cbf56..9e05083 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,6 +49,17 @@ where write!(output, "{bytes}") } +fn trim_end(line: &[u8]) -> usize { + let mut end = line.len(); + for ch in line.iter().rev() { + if *ch != b'\r' && *ch != b'\n' && *ch != b'\t' { + break; + } + end -= 1; + } + end +} + fn run() -> LogtimesResult { let mut log_file = args().nth(1).map(|f| { File::options() @@ -84,12 +95,16 @@ fn run() -> LogtimesResult { if buf[0] == 0xa { print_delete_line(&mut out)?; print_time_color(&mut out)?; - out.write_all(&linebuf)?; + + let end = trim_end(&linebuf); + out.write_all(&linebuf[..end])?; + out.write_all(&[b'\r', b'\n'])?; out.flush()?; if let Some(ref mut f) = log_file { print_time(f)?; - f.write_all(&linebuf)?; + f.write_all(&linebuf[..end])?; + f.write_all(&[b'\n'])?; f.flush()?; };