diff --git a/examples/basic.stdout b/examples/basic.stdout index 6f0b288..b4434c0 100644 --- a/examples/basic.stdout +++ b/examples/basic.stdout @@ -1,5 +1,5 @@ -1:main┐basic::hierarchical-example -1:main┐ version=0.1 +1:main┬─┬─ basic::hierarchical-example +1:main│ └─ version=0.1 1:main├┬─┬─ basic::hierarchical-example 1:main││ └─ version=0.1 1:main│└┬─┬─ basic::server @@ -88,5 +88,5 @@ 1:main││ └─ port=8080 1:main├┴┬─ basic::hierarchical-example 1:main│ └─ version=0.1 -1:main┘basic::hierarchical-example -1:main┘ version=0.1 +1:main┴┬─ basic::hierarchical-example +1:main └─ version=0.1 diff --git a/examples/quiet.stdout b/examples/quiet.stdout index 04aff72..4b43a96 100644 --- a/examples/quiet.stdout +++ b/examples/quiet.stdout @@ -1,5 +1,5 @@ -1:main┐quiet::hierarchical-example -1:main┐ version=0.1 +1:main┬─┬─ quiet::hierarchical-example +1:main│ └─ version=0.1 1:main├─┬─┬─ quiet::server 1:main│ │ ├─ host="localhost" 1:main│ │ └─ port=8080 diff --git a/examples/wraparound.stdout b/examples/wraparound.stdout index 9e82726..4edf577 100644 --- a/examples/wraparound.stdout +++ b/examples/wraparound.stdout @@ -1,5 +1,5 @@ -1:main┐wraparound::recurse -1:main┐ i=0 +1:main┬─┬─ wraparound::recurse +1:main│ └─ i=0 1:main├─ Xms WARN wraparound boop 1:main├─┬─┬─ wraparound::recurse 1:main│ │ └─ i=1 @@ -14,8 +14,8 @@ 1:main│ │ │ │ │ └─ i=4 1:main────────┘ 1:main Xms WARN wraparound boop -1:main┐wraparound::recurse -1:main┐ i=5 +1:main┬─┬─ wraparound::recurse +1:main│ └─ i=5 1:main├─ Xms WARN wraparound boop 1:main├─┬─┬─ wraparound::recurse 1:main│ │ └─ i=6 @@ -30,8 +30,8 @@ 1:main│ │ │ │ │ └─ i=9 1:main────────┘ 1:main Xms WARN wraparound boop -1:main┐wraparound::recurse -1:main┐ i=10 +1:main┬─┬─ wraparound::recurse +1:main│ └─ i=10 1:main├─ Xms WARN wraparound boop 1:main├─┬─┬─ wraparound::recurse 1:main│ │ └─ i=11 @@ -46,8 +46,8 @@ 1:main│ │ │ │ │ └─ i=14 1:main────────┘ 1:main Xms WARN wraparound boop -1:main┐wraparound::recurse -1:main┐ i=15 +1:main┬─┬─ wraparound::recurse +1:main│ └─ i=15 1:main├─ Xms WARN wraparound boop 1:main├─┬─┬─ wraparound::recurse 1:main│ │ └─ i=16 @@ -62,8 +62,8 @@ 1:main│ │ │ │ │ └─ i=19 1:main────────┘ 1:main Xms WARN wraparound boop -1:main┐wraparound::recurse -1:main┐ i=20 +1:main┬─┬─ wraparound::recurse +1:main│ └─ i=20 1:main├─ Xms WARN wraparound boop 1:main├─┬─┬─ wraparound::recurse 1:main│ │ └─ i=21 diff --git a/src/format.rs b/src/format.rs index 73d28a6..d079b75 100644 --- a/src/format.rs +++ b/src/format.rs @@ -266,22 +266,6 @@ fn indent_block_with_lines( let indent_spaces = indent * indent_amount; if lines.is_empty() { return; - } else if indent_spaces == 0 { - for line in lines { - buf.push_str(prefix); - // The first indent is special, we only need to print open/close and nothing else - if indent == 0 { - match style { - SpanMode::Open { .. } => buf.push_str(LINE_OPEN), - SpanMode::Close { .. } => buf.push_str(LINE_CLOSE), - SpanMode::PreOpen | SpanMode::PostClose => {} - SpanMode::Event => {} - } - } - buf.push_str(line); - buf.push('\n'); - } - return; } let mut s = String::with_capacity(indent_spaces + prefix.len()); s.push_str(prefix); @@ -296,7 +280,7 @@ fn indent_block_with_lines( // instead of using all spaces to indent, draw a vertical line at every indent level // up until the last indent - for i in 0..(indent_spaces - indent_amount) { + for i in 0..indent_spaces.saturating_sub(indent_amount) { indent(&mut s, i) } @@ -327,9 +311,11 @@ fn indent_block_with_lines( } } SpanMode::Open { verbose: false } => { - buf.push_str(LINE_BRANCH); - for _ in 1..indent_amount { - buf.push_str(LINE_HORIZ); + if indent_spaces != 0 { + buf.push_str(LINE_BRANCH); + for _ in 1..indent_amount { + buf.push_str(LINE_HORIZ); + } } if lines.len() > 1 { buf.push_str(ARGS_BRANCH); @@ -341,24 +327,29 @@ fn indent_block_with_lines( buf.push_str(LINE_HORIZ); } buf.push_str(" "); - for i in 0..indent_amount { - indent(&mut s, i) + + if indent_spaces != 0 { + for i in 0..indent_amount { + indent(&mut s, i) + } } } else { buf.push_str(LINE_OPEN); } } SpanMode::Open { verbose: true } => { - buf.push_str(LINE_VERT); - for _ in 1..(indent_amount / 2) { - buf.push(' '); - } - // We don't have the space for fancy rendering at single space indent. - if indent_amount > 1 { - buf.push('└'); - } - for _ in (indent_amount / 2)..(indent_amount - 1) { - buf.push_str(LINE_HORIZ); + if indent_spaces != 0 { + buf.push_str(LINE_VERT); + for _ in 1..(indent_amount / 2) { + buf.push(' '); + } + // We don't have the space for fancy rendering at single space indent. + if indent_amount > 1 { + buf.push('└'); + } + for _ in (indent_amount / 2)..(indent_amount - 1) { + buf.push_str(LINE_HORIZ); + } } // We don't have the space for fancy rendering at single space indent. if indent_amount > 1 { @@ -372,8 +363,10 @@ fn indent_block_with_lines( buf.push_str(LINE_HORIZ); } buf.push_str(" "); - for i in 0..indent_amount { - indent(&mut s, i) + if indent_spaces != 0 { + for i in 0..indent_amount { + indent(&mut s, i) + } } } else { buf.push_str(LINE_OPEN); @@ -383,23 +376,27 @@ fn indent_block_with_lines( } } SpanMode::Close { verbose: false } => { - buf.push_str(LINE_BRANCH); - for _ in 1..indent_amount { - buf.push_str(LINE_HORIZ); + if indent_spaces != 0 { + buf.push_str(LINE_BRANCH); + for _ in 1..indent_amount { + buf.push_str(LINE_HORIZ); + } } buf.push_str(LINE_CLOSE); } SpanMode::Close { verbose: true } => { - buf.push_str(LINE_VERT); - for _ in 1..(indent_amount / 2) { - buf.push(' '); - } - // We don't have the space for fancy rendering at single space indent. - if indent_amount > 1 { - buf.push('┌'); - } - for _ in (indent_amount / 2)..(indent_amount - 1) { - buf.push_str(LINE_HORIZ); + if indent_spaces != 0 { + buf.push_str(LINE_VERT); + for _ in 1..(indent_amount / 2) { + buf.push(' '); + } + // We don't have the space for fancy rendering at single space indent. + if indent_amount > 1 { + buf.push('┌'); + } + for _ in (indent_amount / 2)..(indent_amount - 1) { + buf.push_str(LINE_HORIZ); + } } // We don't have the space for fancy rendering at single space indent. if indent_amount > 1 { @@ -413,8 +410,11 @@ fn indent_block_with_lines( buf.push_str(LINE_HORIZ); } buf.push_str(" "); - for i in 0..indent_amount - 1 { - indent(&mut s, i) + + if indent_spaces != 0 { + for i in 0..indent_amount - 1 { + indent(&mut s, i) + } } } else { buf.push_str(LINE_CLOSE); @@ -446,27 +446,40 @@ fn indent_block_with_lines( } } SpanMode::Event => { - buf.push_str(LINE_BRANCH); + if indent_spaces != 0 { + buf.push_str(LINE_BRANCH); + } if lines.len() > 1 { - for _ in 0..(indent_amount - 1) { - buf.push_str(LINE_HORIZ); + if indent_spaces != 0 { + for _ in 0..(indent_amount - 1) { + buf.push_str(LINE_HORIZ); + } } buf.push_str(ARGS_BRANCH); } - // add `indent_amount - 1` horizontal lines before the span/event - for _ in 0..(indent_amount - 1) { - buf.push_str(LINE_HORIZ); + if indent_spaces != 0 { + // add `indent_amount - 1` horizontal lines before the span/event + for _ in 0..(indent_amount - 1) { + buf.push_str(LINE_HORIZ); + } } } } buf.push_str(lines[0]); buf.push('\n'); - // add the rest of the indentation, since we don't want to draw horizontal lines - // for subsequent lines - for i in 0..indent_amount { - indent(&mut s, i) + match style { + SpanMode::Close { verbose: true } if indent_spaces == 0 => { + s.push(' '); + } + _ => { + // add the rest of the indentation, since we don't want to draw horizontal lines + // for subsequent lines + for i in 0..indent_amount { + indent(&mut s, i) + } + } } // add all of the actual content, with each line preceded by the indent string