diff --git a/examples/basic.stdout b/examples/basic.stdout index 2610ec2..4a2d83f 100644 --- a/examples/basic.stdout +++ b/examples/basic.stdout @@ -1,4 +1,4 @@ -1:mainbasic::hierarchical-example version=0.1 +1:main┐basic::hierarchical-example version=0.1 1:main├┐basic::hierarchical-example version=0.1 1:main│└┐basic::server host="localhost", port=8080 1:main│ ├─ms INFO basic starting @@ -38,4 +38,4 @@ 1:main│ ├─ms INFO basic exit 1:main│┌┘basic::server host="localhost", port=8080 1:main├┘basic::hierarchical-example version=0.1 -1:mainbasic::hierarchical-example version=0.1 +1:main┘basic::hierarchical-example version=0.1 diff --git a/examples/quiet.stdout b/examples/quiet.stdout index 4ee111e..9658965 100644 --- a/examples/quiet.stdout +++ b/examples/quiet.stdout @@ -1,4 +1,4 @@ -1:mainquiet::hierarchical-example version=0.1 +1:main┐quiet::hierarchical-example version=0.1 1:main├─┐quiet::server host="localhost", port=8080 1:main│ ├─ms INFO quiet starting 1:main│ ├─ms INFO quiet listening @@ -25,4 +25,4 @@ 1:main│ ├─ms WARN quiet internal error 1:main│ ├─ms INFO quiet exit 1:main├─┘ -1:main +1:main┘ diff --git a/examples/stderr.stderr b/examples/stderr.stderr index b22aa39..0060f26 100644 --- a/examples/stderr.stderr +++ b/examples/stderr.stderr @@ -1,4 +1,4 @@ -fibonacci_seq{to=5} +┐fibonacci_seq{to=5} ├─ms DEBUG Pushing 0 fibonacci ├─┐nth_fibonacci{n=0} │ ├─ms DEBUG Base case @@ -107,5 +107,5 @@ fibonacci_seq{to=5} │ │ ├─┘ │ ├─┘ ├─┘ - +┘ INFO The first 5 fibonacci numbers are [1, 1, 2, 3, 5, 8] diff --git a/examples/wraparound.stdout b/examples/wraparound.stdout index 81b7bc5..bbf4225 100644 --- a/examples/wraparound.stdout +++ b/examples/wraparound.stdout @@ -1,4 +1,4 @@ -1:mainwraparound::recurse i=0 +1:main┐wraparound::recurse i=0 1:main├─ms WARN wraparound boop 1:main├─┐wraparound::recurse i=1 1:main│ ├─ms WARN wraparound boop @@ -7,8 +7,9 @@ 1:main│ │ ├─┐wraparound::recurse i=3 1:main│ │ │ ├─ms WARN wraparound boop 1:main│ │ │ ├─┐wraparound::recurse i=4 +1:main────────┘ 1:mainms WARN wraparound boop -1:mainwraparound::recurse i=5 +1:main┐wraparound::recurse i=5 1:main├─ms WARN wraparound boop 1:main├─┐wraparound::recurse i=6 1:main│ ├─ms WARN wraparound boop @@ -17,8 +18,9 @@ 1:main│ │ ├─┐wraparound::recurse i=8 1:main│ │ │ ├─ms WARN wraparound boop 1:main│ │ │ ├─┐wraparound::recurse i=9 +1:main────────┘ 1:mainms WARN wraparound boop -1:mainwraparound::recurse i=10 +1:main┐wraparound::recurse i=10 1:main├─ms WARN wraparound boop 1:main├─┐wraparound::recurse i=11 1:main│ ├─ms WARN wraparound boop @@ -27,8 +29,9 @@ 1:main│ │ ├─┐wraparound::recurse i=13 1:main│ │ │ ├─ms WARN wraparound boop 1:main│ │ │ ├─┐wraparound::recurse i=14 +1:main────────┘ 1:mainms WARN wraparound boop -1:mainwraparound::recurse i=15 +1:main┐wraparound::recurse i=15 1:main├─ms WARN wraparound boop 1:main├─┐wraparound::recurse i=16 1:main│ ├─ms WARN wraparound boop @@ -37,16 +40,18 @@ 1:main│ │ ├─┐wraparound::recurse i=18 1:main│ │ │ ├─ms WARN wraparound boop 1:main│ │ │ ├─┐wraparound::recurse i=19 +1:main────────┘ 1:mainms WARN wraparound boop -1:mainwraparound::recurse i=20 +1:main┐wraparound::recurse i=20 1:main├─ms WARN wraparound boop 1:main├─┐wraparound::recurse i=21 1:main│ ├─ms WARN wraparound boop 1:main│ ├─ms WARN wraparound bop 1:main├─┘ 1:main├─ms WARN wraparound bop -1:main +1:main┘ 1:mainms WARN wraparound bop +1:main────────┐ 1:main│ │ │ ├─┘ 1:main│ │ │ ├─ms WARN wraparound bop 1:main│ │ ├─┘ @@ -55,8 +60,9 @@ 1:main│ ├─ms WARN wraparound bop 1:main├─┘ 1:main├─ms WARN wraparound bop -1:main +1:main┘ 1:mainms WARN wraparound bop +1:main────────┐ 1:main│ │ │ ├─┘ 1:main│ │ │ ├─ms WARN wraparound bop 1:main│ │ ├─┘ @@ -65,8 +71,9 @@ 1:main│ ├─ms WARN wraparound bop 1:main├─┘ 1:main├─ms WARN wraparound bop -1:main +1:main┘ 1:mainms WARN wraparound bop +1:main────────┐ 1:main│ │ │ ├─┘ 1:main│ │ │ ├─ms WARN wraparound bop 1:main│ │ ├─┘ @@ -75,8 +82,9 @@ 1:main│ ├─ms WARN wraparound bop 1:main├─┘ 1:main├─ms WARN wraparound bop -1:main +1:main┘ 1:mainms WARN wraparound bop +1:main────────┐ 1:main│ │ │ ├─┘ 1:main│ │ │ ├─ms WARN wraparound bop 1:main│ │ ├─┘ @@ -85,4 +93,4 @@ 1:main│ ├─ms WARN wraparound bop 1:main├─┘ 1:main├─ms WARN wraparound bop -1:main +1:main┘ diff --git a/src/format.rs b/src/format.rs index 77202b8..fd1ffc0 100644 --- a/src/format.rs +++ b/src/format.rs @@ -14,6 +14,7 @@ pub(crate) const LINE_BRANCH: &str = "├"; pub(crate) const LINE_CLOSE: &str = "┘"; pub(crate) const LINE_OPEN: &str = "┐"; +#[derive(Copy, Clone)] pub(crate) enum SpanMode { PreOpen, Open { verbose: bool }, @@ -167,17 +168,53 @@ impl Buffers { pub(crate) fn indent_current(&mut self, indent: usize, config: &Config, style: SpanMode) { self.current_buf.push('\n'); + let prefix = config.prefix(); + + // Render something when wraparound occurs so the user is aware of it + if config.indent_lines { + match style { + SpanMode::Close { .. } | SpanMode::PostClose => { + if indent > 0 && (indent + 1) % config.wraparound == 0 { + self.indent_buf.push_str(&prefix); + for _ in 0..(indent % config.wraparound * config.indent_amount) { + self.indent_buf.push_str(LINE_HORIZ); + } + self.indent_buf.push_str(LINE_OPEN); + self.indent_buf.push('\n'); + } + } + _ => {} + } + } + indent_block( &mut self.current_buf, &mut self.indent_buf, indent % config.wraparound, config.indent_amount, config.indent_lines, - &config.prefix(), + &prefix, style, ); self.current_buf.clear(); self.flush_indent_buf(); + + // Render something when wraparound occurs so the user is aware of it + if config.indent_lines { + match style { + SpanMode::PreOpen | SpanMode::Open { .. } => { + if indent > 0 && (indent + 1) % config.wraparound == 0 { + self.current_buf.push_str(&prefix); + for _ in 0..(indent % config.wraparound * config.indent_amount) { + self.current_buf.push_str(LINE_HORIZ); + } + self.current_buf.push_str(LINE_CLOSE); + self.current_buf.push('\n'); + } + } + _ => {} + } + } } } @@ -235,6 +272,15 @@ fn indent_block_with_lines( } 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'); }