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