Skip to content

Commit db999d9

Browse files
committed
Fix first entry and exit field rendering
1 parent 5546d81 commit db999d9

File tree

4 files changed

+88
-75
lines changed

4 files changed

+88
-75
lines changed

examples/basic.stdout

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
1:mainbasic::hierarchical-example
2-
1:main version=0.1
1+
1:main┬─┬─ basic::hierarchical-example
2+
1:main│ └─ version=0.1
33
1:main├┬─┬─ basic::hierarchical-example
44
1:main││ └─ version=0.1
55
1:main│└┬─┬─ basic::server
@@ -88,5 +88,5 @@
8888
1:main││ └─ port=8080
8989
1:main├┴┬─ basic::hierarchical-example
9090
1:main│ └─ version=0.1
91-
1:mainbasic::hierarchical-example
92-
1:main version=0.1
91+
1:main┴┬─ basic::hierarchical-example
92+
1:main └─ version=0.1

examples/quiet.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
1:mainquiet::hierarchical-example
2-
1:main version=0.1
1+
1:main┬─┬─ quiet::hierarchical-example
2+
1:main│ └─ version=0.1
33
1:main├─┬─┬─ quiet::server
44
1:main│ │ ├─ host="localhost"
55
1:main│ │ └─ port=8080

examples/wraparound.stdout

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
1:mainwraparound::recurse
2-
1:main i=0
1+
1:main┬─┬─ wraparound::recurse
2+
1:main│ └─ i=0
33
1:main├─ Xms WARN wraparound boop
44
1:main├─┬─┬─ wraparound::recurse
55
1:main│ │ └─ i=1
@@ -14,8 +14,8 @@
1414
1:main│ │ │ │ │ └─ i=4
1515
1:main────────┘
1616
1:main Xms WARN wraparound boop
17-
1:mainwraparound::recurse
18-
1:main i=5
17+
1:main┬─┬─ wraparound::recurse
18+
1:main│ └─ i=5
1919
1:main├─ Xms WARN wraparound boop
2020
1:main├─┬─┬─ wraparound::recurse
2121
1:main│ │ └─ i=6
@@ -30,8 +30,8 @@
3030
1:main│ │ │ │ │ └─ i=9
3131
1:main────────┘
3232
1:main Xms WARN wraparound boop
33-
1:mainwraparound::recurse
34-
1:main i=10
33+
1:main┬─┬─ wraparound::recurse
34+
1:main│ └─ i=10
3535
1:main├─ Xms WARN wraparound boop
3636
1:main├─┬─┬─ wraparound::recurse
3737
1:main│ │ └─ i=11
@@ -46,8 +46,8 @@
4646
1:main│ │ │ │ │ └─ i=14
4747
1:main────────┘
4848
1:main Xms WARN wraparound boop
49-
1:mainwraparound::recurse
50-
1:main i=15
49+
1:main┬─┬─ wraparound::recurse
50+
1:main│ └─ i=15
5151
1:main├─ Xms WARN wraparound boop
5252
1:main├─┬─┬─ wraparound::recurse
5353
1:main│ │ └─ i=16
@@ -62,8 +62,8 @@
6262
1:main│ │ │ │ │ └─ i=19
6363
1:main────────┘
6464
1:main Xms WARN wraparound boop
65-
1:mainwraparound::recurse
66-
1:main i=20
65+
1:main┬─┬─ wraparound::recurse
66+
1:main│ └─ i=20
6767
1:main├─ Xms WARN wraparound boop
6868
1:main├─┬─┬─ wraparound::recurse
6969
1:main│ │ └─ i=21

src/format.rs

Lines changed: 72 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -267,22 +267,6 @@ fn indent_block_with_lines(
267267
let indent_spaces = indent * indent_amount;
268268
if lines.is_empty() {
269269
return;
270-
} else if indent_spaces == 0 {
271-
for line in lines {
272-
buf.push_str(prefix);
273-
// The first indent is special, we only need to print open/close and nothing else
274-
if indent == 0 {
275-
match style {
276-
SpanMode::Open { .. } => buf.push_str(LINE_OPEN),
277-
SpanMode::Close { .. } => buf.push_str(LINE_CLOSE),
278-
SpanMode::PreOpen | SpanMode::PostClose => {}
279-
SpanMode::Event => {}
280-
}
281-
}
282-
buf.push_str(line);
283-
buf.push('\n');
284-
}
285-
return;
286270
}
287271
let mut s = String::with_capacity(indent_spaces + prefix.len());
288272
s.push_str(prefix);
@@ -297,7 +281,7 @@ fn indent_block_with_lines(
297281

298282
// instead of using all spaces to indent, draw a vertical line at every indent level
299283
// up until the last indent
300-
for i in 0..(indent_spaces - indent_amount) {
284+
for i in 0..indent_spaces.saturating_sub(indent_amount) {
301285
indent(&mut s, i)
302286
}
303287

@@ -328,9 +312,11 @@ fn indent_block_with_lines(
328312
}
329313
}
330314
SpanMode::Open { verbose: false } => {
331-
buf.push_str(LINE_BRANCH);
332-
for _ in 1..indent_amount {
333-
buf.push_str(LINE_HORIZ);
315+
if indent_spaces != 0 {
316+
buf.push_str(LINE_BRANCH);
317+
for _ in 1..indent_amount {
318+
buf.push_str(LINE_HORIZ);
319+
}
334320
}
335321
if lines.len() > 1 {
336322
buf.push_str(ARGS_BRANCH);
@@ -342,24 +328,29 @@ fn indent_block_with_lines(
342328
buf.push_str(LINE_HORIZ);
343329
}
344330
buf.push_str(" ");
345-
for i in 0..indent_amount {
346-
indent(&mut s, i)
331+
332+
if indent_spaces != 0 {
333+
for i in 0..indent_amount {
334+
indent(&mut s, i)
335+
}
347336
}
348337
} else {
349338
buf.push_str(LINE_OPEN);
350339
}
351340
}
352341
SpanMode::Open { verbose: true } => {
353-
buf.push_str(LINE_VERT);
354-
for _ in 1..(indent_amount / 2) {
355-
buf.push(' ');
356-
}
357-
// We don't have the space for fancy rendering at single space indent.
358-
if indent_amount > 1 {
359-
buf.push('└');
360-
}
361-
for _ in (indent_amount / 2)..(indent_amount - 1) {
362-
buf.push_str(LINE_HORIZ);
342+
if indent_spaces != 0 {
343+
buf.push_str(LINE_VERT);
344+
for _ in 1..(indent_amount / 2) {
345+
buf.push(' ');
346+
}
347+
// We don't have the space for fancy rendering at single space indent.
348+
if indent_amount > 1 {
349+
buf.push('└');
350+
}
351+
for _ in (indent_amount / 2)..(indent_amount - 1) {
352+
buf.push_str(LINE_HORIZ);
353+
}
363354
}
364355
// We don't have the space for fancy rendering at single space indent.
365356
if indent_amount > 1 {
@@ -373,8 +364,10 @@ fn indent_block_with_lines(
373364
buf.push_str(LINE_HORIZ);
374365
}
375366
buf.push_str(" ");
376-
for i in 0..indent_amount {
377-
indent(&mut s, i)
367+
if indent_spaces != 0 {
368+
for i in 0..indent_amount {
369+
indent(&mut s, i)
370+
}
378371
}
379372
} else {
380373
buf.push_str(LINE_OPEN);
@@ -384,23 +377,27 @@ fn indent_block_with_lines(
384377
}
385378
}
386379
SpanMode::Close { verbose: false } => {
387-
buf.push_str(LINE_BRANCH);
388-
for _ in 1..indent_amount {
389-
buf.push_str(LINE_HORIZ);
380+
if indent_spaces != 0 {
381+
buf.push_str(LINE_BRANCH);
382+
for _ in 1..indent_amount {
383+
buf.push_str(LINE_HORIZ);
384+
}
390385
}
391386
buf.push_str(LINE_CLOSE);
392387
}
393388
SpanMode::Close { verbose: true } => {
394-
buf.push_str(LINE_VERT);
395-
for _ in 1..(indent_amount / 2) {
396-
buf.push(' ');
397-
}
398-
// We don't have the space for fancy rendering at single space indent.
399-
if indent_amount > 1 {
400-
buf.push('┌');
401-
}
402-
for _ in (indent_amount / 2)..(indent_amount - 1) {
403-
buf.push_str(LINE_HORIZ);
389+
if indent_spaces != 0 {
390+
buf.push_str(LINE_VERT);
391+
for _ in 1..(indent_amount / 2) {
392+
buf.push(' ');
393+
}
394+
// We don't have the space for fancy rendering at single space indent.
395+
if indent_amount > 1 {
396+
buf.push('┌');
397+
}
398+
for _ in (indent_amount / 2)..(indent_amount - 1) {
399+
buf.push_str(LINE_HORIZ);
400+
}
404401
}
405402
// We don't have the space for fancy rendering at single space indent.
406403
if indent_amount > 1 {
@@ -414,8 +411,11 @@ fn indent_block_with_lines(
414411
buf.push_str(LINE_HORIZ);
415412
}
416413
buf.push_str(" ");
417-
for i in 0..indent_amount - 1 {
418-
indent(&mut s, i)
414+
415+
if indent_spaces != 0 {
416+
for i in 0..indent_amount - 1 {
417+
indent(&mut s, i)
418+
}
419419
}
420420
} else {
421421
buf.push_str(LINE_CLOSE);
@@ -447,27 +447,40 @@ fn indent_block_with_lines(
447447
}
448448
}
449449
SpanMode::Event => {
450-
buf.push_str(LINE_BRANCH);
450+
if indent_spaces != 0 {
451+
buf.push_str(LINE_BRANCH);
452+
}
451453
if lines.len() > 1 {
452-
for _ in 0..(indent_amount - 1) {
453-
buf.push_str(LINE_HORIZ);
454+
if indent_spaces != 0 {
455+
for _ in 0..(indent_amount - 1) {
456+
buf.push_str(LINE_HORIZ);
457+
}
454458
}
455459
buf.push_str(ARGS_BRANCH);
456460
}
457461

458-
// add `indent_amount - 1` horizontal lines before the span/event
459-
for _ in 0..(indent_amount - 1) {
460-
buf.push_str(LINE_HORIZ);
462+
if indent_spaces != 0 {
463+
// add `indent_amount - 1` horizontal lines before the span/event
464+
for _ in 0..(indent_amount - 1) {
465+
buf.push_str(LINE_HORIZ);
466+
}
461467
}
462468
}
463469
}
464470
buf.push_str(lines[0]);
465471
buf.push('\n');
466472

467-
// add the rest of the indentation, since we don't want to draw horizontal lines
468-
// for subsequent lines
469-
for i in 0..indent_amount {
470-
indent(&mut s, i)
473+
match style {
474+
SpanMode::Close { verbose: true } if indent_spaces == 0 => {
475+
s.push(' ');
476+
}
477+
_ => {
478+
// add the rest of the indentation, since we don't want to draw horizontal lines
479+
// for subsequent lines
480+
for i in 0..indent_amount {
481+
indent(&mut s, i)
482+
}
483+
}
471484
}
472485

473486
// add all of the actual content, with each line preceded by the indent string

0 commit comments

Comments
 (0)