Skip to content

Commit b8923de

Browse files
align the pipes to the open/close header
1 parent 3559ede commit b8923de

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

examples/basic.stdout

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
1:main ┌┘basic::server host="localhost", port=8080
2222
1:main └┐basic::server host="localhost", port=8080
2323
1:main └┐basic:: val=PrettyPrintMe {
24-
1:main value_a: 42,
25-
1:main value_b: "hello",
26-
1:main }
24+
1:main value_a: 42,
25+
1:main value_b: "hello",
26+
1:main }
2727
1:main ├─ ERROR basic hello
2828
1:main ┌┘basic:: val=PrettyPrintMe {
29-
1:main value_a: 42,
30-
1:main value_b: "hello",
31-
1:main }
29+
1:main value_a: 42,
30+
1:main value_b: "hello",
31+
1:main }
3232
1:main ┌┘basic::server host="localhost", port=8080
3333
1:main └┐basic::server host="localhost", port=8080
3434
1:main └┐basic::conn peer_addr="82.9.9.9", port=42381

examples/no-indent.stdout

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
1:main no_indent::foomp 42 <- format string, normal_var=43
1111
1:main ERROR no_indent hello
1212
1:main no_indent:: val=PrettyPrintMe {
13-
1:main value_a: 42,
14-
1:main value_b: "hello",
15-
1:main }
13+
1:main value_a: 42,
14+
1:main value_b: "hello",
15+
1:main }
1616
1:main ERROR no_indent hello
1717
1:main no_indent::conn peer_addr="82.9.9.9", port=42381
1818
1:main WARN no_indent weak encryption requested, algo="xor"

src/format.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,14 @@ fn indent_block_with_lines(
448448

449449
// add the rest of the indentation, since we don't want to draw horizontal lines
450450
// for subsequent lines
451-
for i in 0..indent_amount {
452-
if i % indent_amount == 0 {
453-
s.push_str(LINE_VERT);
454-
} else {
455-
s.push(' ');
456-
}
451+
match style {
452+
SpanMode::Open { .. } | SpanMode::Retrace { .. } => s.push_str(" "),
453+
SpanMode::Close { .. } => s.push(' '),
454+
_ => {}
455+
}
456+
s.push_str(LINE_VERT);
457+
for _ in 1..=indent_amount {
458+
s.push(' ');
457459
}
458460

459461
// add all of the actual content, with each line preceded by the indent string
@@ -489,11 +491,16 @@ fn indent_block(
489491
if indent_lines {
490492
indent_block_with_lines(&lines, buf, indent, indent_amount, prefix, style);
491493
} else {
492-
let indent_str = String::from(" ").repeat(indent_spaces);
494+
let mut indent_str = " ".repeat(indent_spaces);
495+
let mut first_line = true;
493496
for line in lines {
494497
buf.push_str(prefix);
495498
buf.push(' ');
496499
buf.push_str(&indent_str);
500+
if first_line {
501+
first_line = false;
502+
indent_str.push_str(" ");
503+
}
497504
buf.push_str(line);
498505
buf.push('\n');
499506
}

0 commit comments

Comments
 (0)