| 16 | use std::thread; |
| 17 | |
| 18 | fn forward_process_output_to_stdout<T: std::io::Read>(read: T, prefix: &str, color: Color, atty: bool, mark_err: bool) -> Result<(), AppError> { |
| 19 | let mut buf = BufReader::new(read); |
| 20 | loop { |
| 21 | let mut line = String::new(); |
| 22 | let read: usize = buf.read_line(&mut line)?; |
| 23 | if read == 0 { |
| 24 | break; |
| 25 | } |
| 26 | if mark_err { |
| 27 | let prefix = format!("{:>21.21} |", prefix); |
| 28 | if atty { |
| 29 | print!("{} {} {}", "ERR".red(), prefix.fg(color), line); |
| 30 | } else { |
| 31 | print!("ERR {} {}", prefix, line); |
| 32 | }; |
| 33 | } else { |
| 34 | let prefix = format!("{:>25.25} |", prefix); |
| 35 | if atty { |
| 36 | print!("{} {}", prefix.fg(color), line); |
| 37 | } else { |
| 38 | print!("{} {}", prefix, line); |
| 39 | }; |
| 40 | } |
| 41 | } |
| 42 | Ok(()) |
| 43 | } |
| 44 | |
| 45 | fn is_stdout_a_tty() -> bool { |
| 46 | std::io::stdout().is_terminal() |