@@ -267,22 +267,6 @@ fn indent_block_with_lines(
267
267
let indent_spaces = indent * indent_amount;
268
268
if lines. is_empty ( ) {
269
269
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 ;
286
270
}
287
271
let mut s = String :: with_capacity ( indent_spaces + prefix. len ( ) ) ;
288
272
s. push_str ( prefix) ;
@@ -297,7 +281,7 @@ fn indent_block_with_lines(
297
281
298
282
// instead of using all spaces to indent, draw a vertical line at every indent level
299
283
// 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) {
301
285
indent ( & mut s, i)
302
286
}
303
287
@@ -328,9 +312,11 @@ fn indent_block_with_lines(
328
312
}
329
313
}
330
314
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
+ }
334
320
}
335
321
if lines. len ( ) > 1 {
336
322
buf. push_str ( ARGS_BRANCH ) ;
@@ -342,24 +328,29 @@ fn indent_block_with_lines(
342
328
buf. push_str ( LINE_HORIZ ) ;
343
329
}
344
330
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
+ }
347
336
}
348
337
} else {
349
338
buf. push_str ( LINE_OPEN ) ;
350
339
}
351
340
}
352
341
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
+ }
363
354
}
364
355
// We don't have the space for fancy rendering at single space indent.
365
356
if indent_amount > 1 {
@@ -373,8 +364,10 @@ fn indent_block_with_lines(
373
364
buf. push_str ( LINE_HORIZ ) ;
374
365
}
375
366
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
+ }
378
371
}
379
372
} else {
380
373
buf. push_str ( LINE_OPEN ) ;
@@ -384,23 +377,27 @@ fn indent_block_with_lines(
384
377
}
385
378
}
386
379
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
+ }
390
385
}
391
386
buf. push_str ( LINE_CLOSE ) ;
392
387
}
393
388
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
+ }
404
401
}
405
402
// We don't have the space for fancy rendering at single space indent.
406
403
if indent_amount > 1 {
@@ -414,8 +411,11 @@ fn indent_block_with_lines(
414
411
buf. push_str ( LINE_HORIZ ) ;
415
412
}
416
413
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
+ }
419
419
}
420
420
} else {
421
421
buf. push_str ( LINE_CLOSE ) ;
@@ -447,27 +447,40 @@ fn indent_block_with_lines(
447
447
}
448
448
}
449
449
SpanMode :: Event => {
450
- buf. push_str ( LINE_BRANCH ) ;
450
+ if indent_spaces != 0 {
451
+ buf. push_str ( LINE_BRANCH ) ;
452
+ }
451
453
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
+ }
454
458
}
455
459
buf. push_str ( ARGS_BRANCH ) ;
456
460
}
457
461
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
+ }
461
467
}
462
468
}
463
469
}
464
470
buf. push_str ( lines[ 0 ] ) ;
465
471
buf. push ( '\n' ) ;
466
472
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
+ }
471
484
}
472
485
473
486
// add all of the actual content, with each line preceded by the indent string
0 commit comments