Skip to content

Commit e43cc78

Browse files
committed
display fixes
1 parent 4d2b44f commit e43cc78

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

crates/types/src/output_preimage.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -545,26 +545,49 @@ fn print_formatted_value(value: &Value, abi: Option<&Value>, indent: usize, show
545545
print!("]");
546546
} else if is_enum_array {
547547
// Print enum arrays compactly with multiple values per line (4 per line)
548-
println!("[");
548+
// Calculate column widths for alignment
549549
let items_per_line = 4;
550+
let num_lines = (arr.len() + items_per_line - 1) / items_per_line;
551+
let mut column_widths = vec![0; items_per_line];
552+
553+
// Find maximum width for each column
554+
for (idx, item) in arr.iter().enumerate() {
555+
if let Value::String(s) = item {
556+
let col = idx % items_per_line;
557+
column_widths[col] = column_widths[col].max(s.len());
558+
}
559+
}
560+
561+
println!("[");
550562
let indent_str = " ".repeat(indent);
551563
for (idx, item) in arr.iter().enumerate() {
552564
let is_line_start = idx % items_per_line == 0;
553565
let is_line_end = (idx + 1) % items_per_line == 0 || idx == arr.len() - 1;
566+
let col = idx % items_per_line;
554567

555568
if is_line_start {
556569
print!("{} ", indent_str);
557570
}
558571

559-
print_formatted_value(item, abi, indent, show_struct_names)?;
560-
561-
if idx < arr.len() - 1 {
562-
if is_line_end {
563-
println!(",");
564-
} else {
565-
print!(", ");
572+
// Print value with padding for column alignment
573+
if let Value::String(s) = item {
574+
let width = column_widths[col];
575+
print!("{}\"{}\"{}", BOLD, s, RESET);
576+
if !is_line_end && col < items_per_line - 1 {
577+
// Add padding to align next column
578+
let padding = width.saturating_sub(s.len()) + 2; // +2 for ", "
579+
print!(",{}", " ".repeat(padding));
566580
}
567581
} else {
582+
print_formatted_value(item, abi, indent, show_struct_names)?;
583+
if !is_line_end {
584+
print!(", ");
585+
}
586+
}
587+
588+
if is_line_end {
589+
println!(",");
590+
} else if idx == arr.len() - 1 {
568591
println!();
569592
}
570593
}

0 commit comments

Comments
 (0)