Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Introduce terminal wrap around when explaining plans #2342

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/daft-plan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pyo3-log = {workspace = true, optional = true}
serde = {workspace = true, features = ["rc"]}
serde_json = {workspace = true}
snafu = {workspace = true}
terminal_size = {version = "0.3.0"}
textwrap = {version = "0.16.1"}

[dev-dependencies]
rstest = {workspace = true}
Expand Down
31 changes: 25 additions & 6 deletions src/daft-plan/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,32 @@
} else {
self.get_multiline_representation()
};
for (i, val) in lines.iter().enumerate() {
self.fmt_depth(depth, s)?;
match i {
0 => write!(s, "* ")?,
_ => write!(s, "| ")?,
use terminal_size::{terminal_size, Width};
let size = terminal_size();
let term_width = if let Some((Width(w), _)) = size {
w as usize

Check warning on line 64 in src/daft-plan/src/display.rs

View check run for this annotation

Codecov / codecov/patch

src/daft-plan/src/display.rs#L64

Added line #L64 was not covered by tests
} else {
88usize
};

let mut counter = 0;
for val in lines.iter() {
let base_characters = depth * 2;
let expected_chars = (term_width - base_characters - 8).max(8);
let sublines = textwrap::wrap(val, expected_chars);

for (i, sb) in sublines.iter().enumerate() {
self.fmt_depth(depth, s)?;
match counter {
0 => write!(s, "* ")?,
_ => write!(s, "| ")?,

Check warning on line 79 in src/daft-plan/src/display.rs

View check run for this annotation

Codecov / codecov/patch

src/daft-plan/src/display.rs#L79

Added line #L79 was not covered by tests
}
counter += 1;
match i {
0 => writeln!(s, "{sb}")?,
_ => writeln!(s, " {sb}")?,

Check warning on line 84 in src/daft-plan/src/display.rs

View check run for this annotation

Codecov / codecov/patch

src/daft-plan/src/display.rs#L84

Added line #L84 was not covered by tests
}
}
writeln!(s, "{val}")?;
}

// Recursively handle children.
Expand Down
Loading