Skip to content

Commit 765ee8a

Browse files
committed
Fix first entry and exit field rendering
1 parent a4bd300 commit 765ee8a

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
@@ -266,22 +266,6 @@ fn indent_block_with_lines(
266266
let indent_spaces = indent * indent_amount;
267267
if lines.is_empty() {
268268
return;
269-
} else if indent_spaces == 0 {
270-
for line in lines {
271-
buf.push_str(prefix);
272-
// The first indent is special, we only need to print open/close and nothing else
273-
if indent == 0 {
274-
match style {
275-
SpanMode::Open { .. } => buf.push_str(LINE_OPEN),
276-
SpanMode::Close { .. } => buf.push_str(LINE_CLOSE),
277-
SpanMode::PreOpen | SpanMode::PostClose => {}
278-
SpanMode::Event => {}
279-
}
280-
}
281-
buf.push_str(line);
282-
buf.push('\n');
283-
}
284-
return;
285269
}
286270
let mut s = String::with_capacity(indent_spaces + prefix.len());
287271
s.push_str(prefix);
@@ -296,7 +280,7 @@ fn indent_block_with_lines(
296280

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

@@ -327,9 +311,11 @@ fn indent_block_with_lines(
327311
}
328312
}
329313
SpanMode::Open { verbose: false } => {
330-
buf.push_str(LINE_BRANCH);
331-
for _ in 1..indent_amount {
332-
buf.push_str(LINE_HORIZ);
314+
if indent_spaces != 0 {
315+
buf.push_str(LINE_BRANCH);
316+
for _ in 1..indent_amount {
317+
buf.push_str(LINE_HORIZ);
318+
}
333319
}
334320
if lines.len() > 1 {
335321
buf.push_str(ARGS_BRANCH);
@@ -341,24 +327,29 @@ fn indent_block_with_lines(
341327
buf.push_str(LINE_HORIZ);
342328
}
343329
buf.push_str(" ");
344-
for i in 0..indent_amount {
345-
indent(&mut s, i)
330+
331+
if indent_spaces != 0 {
332+
for i in 0..indent_amount {
333+
indent(&mut s, i)
334+
}
346335
}
347336
} else {
348337
buf.push_str(LINE_OPEN);
349338
}
350339
}
351340
SpanMode::Open { verbose: true } => {
352-
buf.push_str(LINE_VERT);
353-
for _ in 1..(indent_amount / 2) {
354-
buf.push(' ');
355-
}
356-
// We don't have the space for fancy rendering at single space indent.
357-
if indent_amount > 1 {
358-
buf.push('└');
359-
}
360-
for _ in (indent_amount / 2)..(indent_amount - 1) {
361-
buf.push_str(LINE_HORIZ);
341+
if indent_spaces != 0 {
342+
buf.push_str(LINE_VERT);
343+
for _ in 1..(indent_amount / 2) {
344+
buf.push(' ');
345+
}
346+
// We don't have the space for fancy rendering at single space indent.
347+
if indent_amount > 1 {
348+
buf.push('└');
349+
}
350+
for _ in (indent_amount / 2)..(indent_amount - 1) {
351+
buf.push_str(LINE_HORIZ);
352+
}
362353
}
363354
// We don't have the space for fancy rendering at single space indent.
364355
if indent_amount > 1 {
@@ -372,8 +363,10 @@ fn indent_block_with_lines(
372363
buf.push_str(LINE_HORIZ);
373364
}
374365
buf.push_str(" ");
375-
for i in 0..indent_amount {
376-
indent(&mut s, i)
366+
if indent_spaces != 0 {
367+
for i in 0..indent_amount {
368+
indent(&mut s, i)
369+
}
377370
}
378371
} else {
379372
buf.push_str(LINE_OPEN);
@@ -383,23 +376,27 @@ fn indent_block_with_lines(
383376
}
384377
}
385378
SpanMode::Close { verbose: false } => {
386-
buf.push_str(LINE_BRANCH);
387-
for _ in 1..indent_amount {
388-
buf.push_str(LINE_HORIZ);
379+
if indent_spaces != 0 {
380+
buf.push_str(LINE_BRANCH);
381+
for _ in 1..indent_amount {
382+
buf.push_str(LINE_HORIZ);
383+
}
389384
}
390385
buf.push_str(LINE_CLOSE);
391386
}
392387
SpanMode::Close { verbose: true } => {
393-
buf.push_str(LINE_VERT);
394-
for _ in 1..(indent_amount / 2) {
395-
buf.push(' ');
396-
}
397-
// We don't have the space for fancy rendering at single space indent.
398-
if indent_amount > 1 {
399-
buf.push('┌');
400-
}
401-
for _ in (indent_amount / 2)..(indent_amount - 1) {
402-
buf.push_str(LINE_HORIZ);
388+
if indent_spaces != 0 {
389+
buf.push_str(LINE_VERT);
390+
for _ in 1..(indent_amount / 2) {
391+
buf.push(' ');
392+
}
393+
// We don't have the space for fancy rendering at single space indent.
394+
if indent_amount > 1 {
395+
buf.push('┌');
396+
}
397+
for _ in (indent_amount / 2)..(indent_amount - 1) {
398+
buf.push_str(LINE_HORIZ);
399+
}
403400
}
404401
// We don't have the space for fancy rendering at single space indent.
405402
if indent_amount > 1 {
@@ -413,8 +410,11 @@ fn indent_block_with_lines(
413410
buf.push_str(LINE_HORIZ);
414411
}
415412
buf.push_str(" ");
416-
for i in 0..indent_amount - 1 {
417-
indent(&mut s, i)
413+
414+
if indent_spaces != 0 {
415+
for i in 0..indent_amount - 1 {
416+
indent(&mut s, i)
417+
}
418418
}
419419
} else {
420420
buf.push_str(LINE_CLOSE);
@@ -446,27 +446,40 @@ fn indent_block_with_lines(
446446
}
447447
}
448448
SpanMode::Event => {
449-
buf.push_str(LINE_BRANCH);
449+
if indent_spaces != 0 {
450+
buf.push_str(LINE_BRANCH);
451+
}
450452
if lines.len() > 1 {
451-
for _ in 0..(indent_amount - 1) {
452-
buf.push_str(LINE_HORIZ);
453+
if indent_spaces != 0 {
454+
for _ in 0..(indent_amount - 1) {
455+
buf.push_str(LINE_HORIZ);
456+
}
453457
}
454458
buf.push_str(ARGS_BRANCH);
455459
}
456460

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

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

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

0 commit comments

Comments
 (0)