Improved live logging

This commit is contained in:
Ultradesu
2025-06-27 14:14:04 +03:00
parent ce76efad12
commit b090b299c7
3 changed files with 20 additions and 7 deletions

2
Cargo.lock generated
View File

@ -401,7 +401,7 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "rexec"
version = "1.4.0"
version = "1.5.0"
dependencies = [
"brace-expand",
"clap",

View File

@ -1,6 +1,6 @@
[package]
name = "rexec"
version = "1.5.0"
version = "1.5.1"
readme = "https://github.com/house-of-vanity/rexec#readme"
edition = "2021"
description = "Parallel SSH executor"

View File

@ -315,7 +315,7 @@ fn execute_ssh_command(
};
// Function to handle output lines with proper block management
let handle_output = |line: String, display_name: &str, code_only: bool| {
let handle_output = |line: String, display_name: &str, code_only: bool, is_stderr: bool| {
if !code_only {
let mut current_block = CURRENT_BLOCK.lock().unwrap();
@ -338,8 +338,19 @@ fn execute_ssh_command(
}
}
// Print the log line
println!("{}{}", display_name.yellow(), line);
// Print the log line with colored separator based on stream type
let separator = if is_stderr {
"".red()
} else {
"".green()
};
println!(
"{} {} {} {}",
separator,
display_name.yellow(),
separator,
line
);
}
};
@ -353,7 +364,8 @@ fn execute_ssh_command(
for line in reader.lines() {
match line {
Ok(line) => {
handle_output(line, &display_name_stdout, code_only_stdout);
handle_output(line, &display_name_stdout, code_only_stdout, false);
// false = stdout
}
Err(_) => break,
}
@ -370,7 +382,8 @@ fn execute_ssh_command(
for line in reader.lines() {
match line {
Ok(line) => {
handle_output(line, &display_name_stderr, code_only_stderr);
handle_output(line, &display_name_stderr, code_only_stderr, true);
// true = stderr
}
Err(_) => break,
}