Skip to content

Commit 08fcdd1

Browse files
committed
feat(api): remove max_depth from visualizer
1 parent a67e019 commit 08fcdd1

10 files changed

Lines changed: 5 additions & 52 deletions

File tree

src/app.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ impl App {
5757
bytes_format,
5858
top_down,
5959
align_right,
60-
max_depth,
6160
..
6261
} = self.args;
6362
let direction = Direction::from_top_down(top_down);
@@ -79,7 +78,6 @@ impl App {
7978
column_width_distribution,
8079
direction,
8180
bar_alignment,
82-
max_depth,
8381
}
8482
.to_string()
8583
}};

src/app/sub.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ where
144144
direction,
145145
bar_alignment,
146146
column_width_distribution,
147-
max_depth,
148147
};
149148

150149
print!("{visualizer}"); // visualizer already ends with "\n", println! isn't needed here.

src/visualizer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use proportion_bar::{ProportionBar, ProportionBarBlock};
1515
pub use tree::{TreeHorizontalSlice, TreeSkeletalComponent};
1616

1717
use super::{data_tree::DataTree, size};
18-
use std::{fmt::Display, num::NonZeroUsize};
18+
use std::fmt::Display;
1919

2020
/// Visualize a [`DataTree`].
2121
///
@@ -59,8 +59,6 @@ where
5959
pub bar_alignment: BarAlignment,
6060
/// Distribution and total number of characters/blocks can be placed in a line.
6161
pub column_width_distribution: ColumnWidthDistribution,
62-
/// Maximum number of levels that should be visualized.
63-
pub max_depth: NonZeroUsize,
6462
}
6563

6664
mod copy;

src/visualizer/methods/initial_table.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ where
4646
{
4747
#[derive(Clone)]
4848
struct Param<Name, NodeData> {
49-
remaining_depth: usize,
5049
index_as_child: usize,
5150
ancestors: Vec<NodeInfo<Name, NodeData>>,
5251
preceding_sibling: Option<NodeInfo<Name, NodeData>>,
@@ -69,11 +68,7 @@ where
6968
Size: size::Size,
7069
Act: FnMut(&'a DataTree<Name, Size>, Param<&'a Name, Size>) -> ActResult<&'a Name, Size>,
7170
{
72-
if param.remaining_depth == 0 {
73-
return None;
74-
}
7571
let ActResult { node_info } = act(tree, param.clone());
76-
let remaining_depth = param.remaining_depth - 1;
7772
let mut preceding_sibling = None;
7873
for (index_as_child, child) in tree.children().iter().enumerate() {
7974
let mut ancestors = Vec::with_capacity(param.ancestors.len() + 1);
@@ -83,7 +78,6 @@ where
8378
child,
8479
act,
8580
Param {
86-
remaining_depth,
8781
index_as_child,
8882
ancestors,
8983
preceding_sibling,
@@ -103,18 +97,12 @@ where
10397
let Param {
10498
index_as_child,
10599
ancestors,
106-
remaining_depth,
107100
preceding_sibling,
108101
} = param;
109102
let name = node.name();
110103
let node_data = node.size();
111104
let row_index = initial_table.len();
112-
debug_assert_op!(remaining_depth > 0);
113-
let children_count = if remaining_depth != 1 {
114-
node.children().len()
115-
} else {
116-
0
117-
};
105+
let children_count = node.children().len();
118106
let fs_size = node.size().into();
119107
let percentage = if total_fs_size == 0 {
120108
"0%".to_string()
@@ -134,7 +122,6 @@ where
134122
sibling_count,
135123
index_as_child,
136124
children_count,
137-
remaining_depth,
138125
};
139126

140127
initial_table.column_width.size_column_width =
@@ -151,7 +138,6 @@ where
151138
ActResult { node_info }
152139
},
153140
Param {
154-
remaining_depth: visualizer.max_depth.get(),
155141
index_as_child: 0,
156142
ancestors: Vec::new(),
157143
preceding_sibling: None,

src/visualizer/methods/node_info.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ pub struct NodeInfo<Name, NodeData> {
88
pub sibling_count: NonZeroUsize,
99
pub index_as_child: usize,
1010
pub children_count: usize,
11-
pub remaining_depth: usize,
1211
}

src/visualizer/methods/tree_table.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ where
6565
.map(|initial_row| {
6666
let child_position =
6767
ChildPosition::from_index(initial_row.index_as_child, initial_row.sibling_count);
68-
let parenthood = if initial_row.remaining_depth == 0 {
69-
Parenthood::Childless
70-
} else {
71-
Parenthood::from_children_count(initial_row.children_count)
72-
};
68+
let parenthood = Parenthood::from_children_count(initial_row.children_count);
7369
let skeletal_component = TreeSkeletalComponent {
7470
child_position,
7571
parenthood,

tests/cli_errors.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use pipe_trait::Pipe;
1818
use pretty_assertions::assert_eq;
1919
use std::{
2020
collections::BTreeSet,
21-
convert::TryInto,
2221
path::Path,
2322
process::{Command, Output, Stdio},
2423
};
@@ -144,7 +143,6 @@ fn fs_errors() {
144143
direction: Direction::BottomUp,
145144
bar_alignment: BarAlignment::Left,
146145
column_width_distribution: ColumnWidthDistribution::total(100),
147-
max_depth: 10.try_into().unwrap(),
148146
};
149147
let expected_stdout = format!("{visualizer}");
150148
eprintln!("EXPECTED STDOUT:\n{}\n", &expected_stdout);

tests/json.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ fn json_input() {
134134
direction: Direction::BottomUp,
135135
bar_alignment: BarAlignment::Left,
136136
column_width_distribution: ColumnWidthDistribution::total(100),
137-
max_depth: 10.try_into().unwrap(),
138137
};
139138
let expected = format!("{visualizer}");
140139
let expected = expected.trim_end();

tests/usual_cli.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ use parallel_disk_usage::{
1515
};
1616
use pipe_trait::Pipe;
1717
use pretty_assertions::assert_eq;
18-
use std::{
19-
convert::TryInto,
20-
process::{Command, Stdio},
21-
};
18+
use std::process::{Command, Stdio};
2219

2320
fn stdio(command: Command) -> Command {
2421
command
@@ -55,7 +52,6 @@ fn total_width() {
5552
direction: Direction::BottomUp,
5653
bar_alignment: BarAlignment::Left,
5754
column_width_distribution: ColumnWidthDistribution::total(100),
58-
max_depth: 10.try_into().unwrap(),
5955
};
6056
let expected = format!("{visualizer}");
6157
let expected = expected.trim_end();
@@ -94,7 +90,6 @@ fn column_width() {
9490
direction: Direction::BottomUp,
9591
bar_alignment: BarAlignment::Left,
9692
column_width_distribution: ColumnWidthDistribution::components(10, 90),
97-
max_depth: 10.try_into().unwrap(),
9893
};
9994
let expected = format!("{visualizer}");
10095
let expected = expected.trim_end();
@@ -132,7 +127,6 @@ fn min_ratio_0() {
132127
direction: Direction::BottomUp,
133128
bar_alignment: BarAlignment::Left,
134129
column_width_distribution: ColumnWidthDistribution::total(100),
135-
max_depth: 10.try_into().unwrap(),
136130
};
137131
let expected = format!("{visualizer}");
138132
let expected = expected.trim_end();
@@ -171,7 +165,6 @@ fn min_ratio() {
171165
direction: Direction::BottomUp,
172166
bar_alignment: BarAlignment::Left,
173167
column_width_distribution: ColumnWidthDistribution::total(100),
174-
max_depth: 10.try_into().unwrap(),
175168
};
176169
let expected = format!("{visualizer}");
177170
let expected = expected.trim_end();
@@ -210,7 +203,6 @@ fn max_depth_2() {
210203
direction: Direction::BottomUp,
211204
bar_alignment: BarAlignment::Left,
212205
column_width_distribution: ColumnWidthDistribution::total(100),
213-
max_depth: 2.try_into().unwrap(),
214206
};
215207
let expected = format!("{visualizer}");
216208
let expected = expected.trim_end();
@@ -249,7 +241,6 @@ fn max_depth_1() {
249241
direction: Direction::BottomUp,
250242
bar_alignment: BarAlignment::Left,
251243
column_width_distribution: ColumnWidthDistribution::total(100),
252-
max_depth: 1.try_into().unwrap(),
253244
};
254245
let expected = format!("{visualizer}");
255246
let expected = expected.trim_end();
@@ -287,7 +278,6 @@ fn top_down() {
287278
direction: Direction::TopDown,
288279
bar_alignment: BarAlignment::Left,
289280
column_width_distribution: ColumnWidthDistribution::total(100),
290-
max_depth: 10.try_into().unwrap(),
291281
};
292282
let expected = format!("{visualizer}");
293283
let expected = expected.trim_end();
@@ -325,7 +315,6 @@ fn align_right() {
325315
direction: Direction::BottomUp,
326316
bar_alignment: BarAlignment::Right,
327317
column_width_distribution: ColumnWidthDistribution::total(100),
328-
max_depth: 10.try_into().unwrap(),
329318
};
330319
let expected = format!("{visualizer}");
331320
let expected = expected.trim_end();
@@ -363,7 +352,6 @@ fn quantity_apparent_size() {
363352
direction: Direction::BottomUp,
364353
bar_alignment: BarAlignment::Left,
365354
column_width_distribution: ColumnWidthDistribution::total(100),
366-
max_depth: 10.try_into().unwrap(),
367355
};
368356
let expected = format!("{visualizer}");
369357
let expected = expected.trim_end();
@@ -402,7 +390,6 @@ fn quantity_block_size() {
402390
direction: Direction::BottomUp,
403391
bar_alignment: BarAlignment::Left,
404392
column_width_distribution: ColumnWidthDistribution::total(100),
405-
max_depth: 10.try_into().unwrap(),
406393
};
407394
let expected = format!("{visualizer}");
408395
let expected = expected.trim_end();
@@ -441,7 +428,6 @@ fn quantity_block_count() {
441428
direction: Direction::BottomUp,
442429
bar_alignment: BarAlignment::Left,
443430
column_width_distribution: ColumnWidthDistribution::total(100),
444-
max_depth: 10.try_into().unwrap(),
445431
};
446432
let expected = format!("{visualizer}");
447433
let expected = expected.trim_end();
@@ -481,7 +467,6 @@ fn bytes_format_plain() {
481467
direction: Direction::BottomUp,
482468
bar_alignment: BarAlignment::Left,
483469
column_width_distribution: ColumnWidthDistribution::total(100),
484-
max_depth: 10.try_into().unwrap(),
485470
};
486471
let expected = format!("{visualizer}");
487472
let expected = expected.trim_end();
@@ -521,7 +506,6 @@ fn bytes_format_metric() {
521506
direction: Direction::BottomUp,
522507
bar_alignment: BarAlignment::Left,
523508
column_width_distribution: ColumnWidthDistribution::total(100),
524-
max_depth: 10.try_into().unwrap(),
525509
};
526510
let expected = format!("{visualizer}");
527511
let expected = expected.trim_end();
@@ -561,7 +545,6 @@ fn bytes_format_binary() {
561545
direction: Direction::BottomUp,
562546
bar_alignment: BarAlignment::Left,
563547
column_width_distribution: ColumnWidthDistribution::total(100),
564-
max_depth: 10.try_into().unwrap(),
565548
};
566549
let expected = format!("{visualizer}");
567550
let expected = expected.trim_end();
@@ -598,7 +581,6 @@ fn path_to_workspace() {
598581
direction: Direction::BottomUp,
599582
bar_alignment: BarAlignment::Left,
600583
column_width_distribution: ColumnWidthDistribution::total(100),
601-
max_depth: 10.try_into().unwrap(),
602584
};
603585
let expected = format!("{visualizer}");
604586
let expected = expected.trim_end();
@@ -652,7 +634,6 @@ fn multiple_names() {
652634
direction: Direction::BottomUp,
653635
bar_alignment: BarAlignment::Left,
654636
column_width_distribution: ColumnWidthDistribution::total(100),
655-
max_depth: 10.try_into().unwrap(),
656637
};
657638
let expected = format!("{visualizer}");
658639
let expected = expected.trim_end();

tests/visualizer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ macro_rules! test_case {
3636
let tree = $tree;
3737
let column_width_distribution =
3838
ColumnWidthDistribution::$column_width_function($($column_width_arguments),+);
39-
let max_depth = NonZeroUsize::new($max_depth).expect("non-zero max_depth");
39+
let _max_depth = NonZeroUsize::new($max_depth).expect("non-zero max_depth"); // TODO: remove later
4040
let actual = Visualizer {
41-
max_depth,
4241
column_width_distribution,
4342
data_tree: &tree,
4443
bytes_format: $bytes_format,

0 commit comments

Comments
 (0)