Skip to content

Commit

Permalink
[FEAT] Introduce terminal wrap around when explaining plans (#2342)
Browse files Browse the repository at this point in the history
Introduces text wrapping when explaining a plan:


![image](https://github.com/Eventual-Inc/Daft/assets/2550285/130177a9-0fb6-454a-bf8d-be4e2ab64987)
  • Loading branch information
samster25 authored Jun 5, 2024
1 parent 8a789be commit 6c84ae8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
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 @@ pub(crate) trait TreeDisplay {
} 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
} 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, "| ")?,
}
counter += 1;
match i {
0 => writeln!(s, "{sb}")?,
_ => writeln!(s, " {sb}")?,
}
}
writeln!(s, "{val}")?;
}

// Recursively handle children.
Expand Down

0 comments on commit 6c84ae8

Please sign in to comment.