Skip to content

Commit a83712f

Browse files
committed
refactor: streamline subprocess.run arguments and improve formatting in UpdateStats display
1 parent 47fc7f0 commit a83712f

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

examples/custom_output_files/run_and_capture.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
# Run main.py and capture output
88
result = subprocess.run(
9-
[sys.executable, "main.py"],
10-
capture_output=True,
11-
text=True,
12-
timeout=10
9+
[sys.executable, "main.py"], capture_output=True, text=True, timeout=10
1310
)
1411

1512
# Write both stdout and stderr to test_output.txt

src/execution/stats.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ impl std::fmt::Display for UpdateStats {
236236
if num_errors > 0 {
237237
let tty = is_stdout_tty();
238238
if tty {
239-
write!(f, "{}", format!("{} rows failed", num_errors).color(AnsiColors::White))?;
239+
write!(
240+
f,
241+
"{}",
242+
format!("{} rows failed", num_errors).color(AnsiColors::White)
243+
)?;
240244
} else {
241245
write!(f, "{} rows failed", num_errors)?;
242246
}
@@ -262,7 +266,8 @@ impl std::fmt::Display for UpdateStats {
262266
let width = std::cmp::min(segment_width, remaining_width);
263267
if width > 0 {
264268
// Calculate completed and remaining portions
265-
let completed_portion = (width as f64 * (total - num_in_process) as f64 / total as f64) as usize;
269+
let completed_portion =
270+
(width as f64 * (total - num_in_process) as f64 / total as f64) as usize;
266271
let remaining_portion = width - completed_portion;
267272

268273
// Add segment with appropriate characters based on type
@@ -271,7 +276,7 @@ impl std::fmt::Display for UpdateStats {
271276
"+" => "█",
272277
"-" => "▓",
273278
"~" => "▒",
274-
_ => "░"
279+
_ => "░",
275280
};
276281
bar.push_str(&completed_char.repeat(completed_portion));
277282
}
@@ -281,7 +286,7 @@ impl std::fmt::Display for UpdateStats {
281286
"+" => "▒",
282287
"-" => "░",
283288
"~" => "░",
284-
_ => " "
289+
_ => " ",
285290
};
286291
bar.push_str(&remaining_char.repeat(remaining_portion));
287292
}
@@ -295,7 +300,13 @@ impl std::fmt::Display for UpdateStats {
295300
let tty = is_stdout_tty();
296301
// Use total from current operations - this represents the actual record count
297302
if tty {
298-
write!(f, "[{}] {}/{} records ", bar.color(AnsiColors::BrightBlack), total - num_in_process, total)?;
303+
write!(
304+
f,
305+
"[{}] {}/{} records ",
306+
bar.color(AnsiColors::BrightBlack),
307+
total - num_in_process,
308+
total
309+
)?;
299310
} else {
300311
write!(f, "[{}] {}/{} records ", bar, total - num_in_process, total)?;
301312
}
@@ -309,10 +320,10 @@ impl std::fmt::Display for UpdateStats {
309320
}
310321
if tty {
311322
match *segment_type {
312-
"+" => write!(f, "{}", label.color(AnsiColors::BrightBlack))?, // Lightest grey for additions
313-
"-" => write!(f, "{}", label.color(AnsiColors::White))?, // White for removals
314-
"~" => write!(f, "{}", label.color(AnsiColors::Black))?, // Dark grey for updates
315-
_ => write!(f, "{}", label.color(AnsiColors::Black))?, // Black for no-change
323+
"+" => write!(f, "{}", label.color(AnsiColors::BrightBlack))?, // Lightest grey for additions
324+
"-" => write!(f, "{}", label.color(AnsiColors::White))?, // White for removals
325+
"~" => write!(f, "{}", label.color(AnsiColors::Black))?, // Dark grey for updates
326+
_ => write!(f, "{}", label.color(AnsiColors::Black))?, // Black for no-change
316327
}
317328
} else {
318329
write!(f, "{}", label)?;
@@ -331,7 +342,11 @@ impl std::fmt::Display for UpdateStats {
331342
}
332343
let tty = is_stdout_tty();
333344
if tty {
334-
write!(f, "{}", format!("({} in process)", num_in_process).color(AnsiColors::Black))?;
345+
write!(
346+
f,
347+
"{}",
348+
format!("({} in process)", num_in_process).color(AnsiColors::Black)
349+
)?;
335350
} else {
336351
write!(f, "({} in process)", num_in_process)?;
337352
}

0 commit comments

Comments
 (0)