Skip to content

Commit

Permalink
Render lines for wraparound to make it more obvious when it happens
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Mar 4, 2021
1 parent df9ce0c commit 4756e44
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
8 changes: 8 additions & 0 deletions examples/wraparound.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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:main┐wraparound::recurse i=5
1:main├─ms WARN wraparound boop
Expand All @@ -17,6 +18,7 @@
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:main┐wraparound::recurse i=10
1:main├─ms WARN wraparound boop
Expand All @@ -27,6 +29,7 @@
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:main┐wraparound::recurse i=15
1:main├─ms WARN wraparound boop
Expand All @@ -37,6 +40,7 @@
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:main┐wraparound::recurse i=20
1:main├─ms WARN wraparound boop
Expand All @@ -47,6 +51,7 @@
1:main├─ms WARN wraparound bop
1:main┘
1:mainms WARN wraparound bop
1:main────────┐
1:main│ │ │ ├─┘
1:main│ │ │ ├─ms WARN wraparound bop
1:main│ │ ├─┘
Expand All @@ -57,6 +62,7 @@
1:main├─ms WARN wraparound bop
1:main┘
1:mainms WARN wraparound bop
1:main────────┐
1:main│ │ │ ├─┘
1:main│ │ │ ├─ms WARN wraparound bop
1:main│ │ ├─┘
Expand All @@ -67,6 +73,7 @@
1:main├─ms WARN wraparound bop
1:main┘
1:mainms WARN wraparound bop
1:main────────┐
1:main│ │ │ ├─┘
1:main│ │ │ ├─ms WARN wraparound bop
1:main│ │ ├─┘
Expand All @@ -77,6 +84,7 @@
1:main├─ms WARN wraparound bop
1:main┘
1:mainms WARN wraparound bop
1:main────────┐
1:main│ │ │ ├─┘
1:main│ │ │ ├─ms WARN wraparound bop
1:main│ │ ├─┘
Expand Down
39 changes: 38 additions & 1 deletion src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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');
}
}
_ => {}
}
}
}
}

Expand Down

0 comments on commit 4756e44

Please sign in to comment.