MCPcopy Create free account
hub / github.com/brocode/fw / forward_process_output_to_stdout

Function forward_process_output_to_stdout

src/spawn/mod.rs:18–43  ·  view source on GitHub ↗
(read: T, prefix: &str, color: Color, atty: bool, mark_err: bool)

Source from the content-addressed store, hash-verified

16use std::thread;
17
18fn 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
45fn is_stdout_a_tty() -> bool {
46 std::io::stdout().is_terminal()

Callers 1

spawn_maybeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected