summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-02-05 08:06:42 +0100
committerCanop <cano.petrole@gmail.com>2021-02-05 08:09:42 +0100
commit8f66f4b376d31fcf792b7716fdca704deb23ef90 (patch)
tree22cdc75d9daf202a21dcee0a14e29cf7388e3851
parentab89b0b2718c7d28f928c47d20feb38d764ccbb5 (diff)
limit tree height in :pt even when there's more root items
The old behavior might be useful but isn't clear enough. I'll restore it otherwise if needed. Fix #341
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/display/displayable_tree.rs3
-rw-r--r--src/launchable.rs6
-rw-r--r--src/print.rs8
4 files changed, 14 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 72f43d6..aa8d381 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
### next
- special paths in "no-enter" or "hide" aren't counted when summing sizes or dates. It's a compromise: it makes all sums a little slower, especially if you have a lot of special paths or complex ones, but it allows skipping over the very slow disks and thus makes some cases much faster - Fix #331
- br fish shell function uses shell completion of broot
+- tree height in `:pt` now applies even when there are more root items (thus truncating the tree) - Fix #341
<a name="v1.2.1"></a>
### v1.2.1 - 2021-01-27
diff --git a/src/display/displayable_tree.rs b/src/display/displayable_tree.rs
index 9882042..86361f8 100644
--- a/src/display/displayable_tree.rs
+++ b/src/display/displayable_tree.rs
@@ -49,6 +49,7 @@ impl<'s, 't> DisplayableTree<'s, 't> {
skin: &'s StyleMap,
ext_colors: &'s ExtColorMap,
width: u16,
+ height: u16,
) -> DisplayableTree<'s, 't> {
DisplayableTree {
tree,
@@ -58,7 +59,7 @@ impl<'s, 't> DisplayableTree<'s, 't> {
left: 0,
top: 0,
width,
- height: tree.lines.len() as u16,
+ height,
},
in_app: false,
}
diff --git a/src/launchable.rs b/src/launchable.rs
index e3cf666..a4096ae 100644
--- a/src/launchable.rs
+++ b/src/launchable.rs
@@ -44,6 +44,7 @@ pub enum Launchable {
skin: Box<StyleMap>,
ext_colors: ExtColorMap,
width: u16,
+ height: u16,
},
/// execute an external program
@@ -94,6 +95,7 @@ impl Launchable {
skin: Box::new(style_map),
ext_colors,
width: screen.width,
+ height: (tree.lines.len() as u16).min(screen.height),
}
}
@@ -123,8 +125,8 @@ impl Launchable {
println!("{}", to_print);
Ok(())
}
- Launchable::TreePrinter { tree, skin, ext_colors, width } => {
- let dp = DisplayableTree::out_of_app(&tree, &skin, &ext_colors, *width);
+ Launchable::TreePrinter { tree, skin, ext_colors, width, height } => {
+ let dp = DisplayableTree::out_of_app(&tree, &skin, &ext_colors, *width, *height);
dp.write_on(&mut std::io::stdout())
}
Launchable::Program {
diff --git a/src/print.rs b/src/print.rs
index 85e04b4..17c72ed 100644
--- a/src/print.rs
+++ b/src/print.rs
@@ -59,7 +59,13 @@ fn print_tree_to_file(
ext_colors: &ExtColorMap,
) -> Result<AppStateCmdResult, ProgramError> {
let no_style_skin = StyleMap::no_term();
- let dp = DisplayableTree::out_of_app(tree, &no_style_skin, ext_colors, screen.width);
+ let dp = DisplayableTree::out_of_app(
+ tree,
+ &no_style_skin,
+ ext_colors,
+ screen.width,
+ (tree.lines.len() as u16).min(screen.height),
+ );
let mut f = OpenOptions::new()
.create(true)
.append(true)