Skip to content

Commit

Permalink
Fix first entry and exit field rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed May 23, 2023
1 parent a4bd300 commit 765ee8a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 75 deletions.
8 changes: 4 additions & 4 deletions examples/basic.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1:mainbasic::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
Expand Down Expand Up @@ -88,5 +88,5 @@
1:main││ └─ port=8080
1:main├┴┬─ basic::hierarchical-example
1:main│ └─ version=0.1
1:mainbasic::hierarchical-example
1:main version=0.1
1:main┴┬─ basic::hierarchical-example
1:main └─ version=0.1
4 changes: 2 additions & 2 deletions examples/quiet.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1:mainquiet::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
Expand Down
20 changes: 10 additions & 10 deletions examples/wraparound.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1:mainwraparound::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
Expand All @@ -14,8 +14,8 @@
1:main│ │ │ │ │ └─ i=4
1:main────────┘
1:main Xms WARN wraparound boop
1:mainwraparound::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
Expand All @@ -30,8 +30,8 @@
1:main│ │ │ │ │ └─ i=9
1:main────────┘
1:main Xms WARN wraparound boop
1:mainwraparound::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
Expand All @@ -46,8 +46,8 @@
1:main│ │ │ │ │ └─ i=14
1:main────────┘
1:main Xms WARN wraparound boop
1:mainwraparound::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
Expand All @@ -62,8 +62,8 @@
1:main│ │ │ │ │ └─ i=19
1:main────────┘
1:main Xms WARN wraparound boop
1:mainwraparound::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
Expand Down
131 changes: 72 additions & 59 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
}

Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 765ee8a

Please sign in to comment.