Skip to content

Commit

Permalink
Merge pull request #230 from KSXGitHub/default-alignment-to-left
Browse files Browse the repository at this point in the history
Make left alignment the default alignment
  • Loading branch information
KSXGitHub authored Mar 10, 2023
2 parents ef89489 + 3e029a7 commit be80dc1
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion exports/completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _pdu() {

case "${cmd}" in
pdu)
opts="-h -V --json-input --json-output --bytes-format --top-down --align-left --quantity --max-depth --total-width --column-width --min-ratio --no-sort --silent-errors --progress --help --version [FILES]..."
opts="-h -V --json-input --json-output --bytes-format --top-down --align-right --quantity --max-depth --total-width --column-width --min-ratio --no-sort --silent-errors --progress --help --version [FILES]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
2 changes: 1 addition & 1 deletion exports/completion.elv
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set edit:completion:arg-completer[pdu] = {|@words|
cand --json-input 'Read JSON data from stdin'
cand --json-output 'Print JSON data instead of an ASCII chart'
cand --top-down 'Print the tree top-down instead of bottom-up'
cand --align-left 'Fill the bars from left to right'
cand --align-right 'Set the root of the bars to the right'
cand --no-sort 'Preserve order of entries'
cand --silent-errors 'Prevent filesystem error messages from appearing in stderr'
cand --progress 'Report progress being made at the expense of performance'
Expand Down
2 changes: 1 addition & 1 deletion exports/completion.fish
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ complete -c pdu -l min-ratio -d 'Minimal size proportion required to appear' -r
complete -c pdu -l json-input -d 'Read JSON data from stdin'
complete -c pdu -l json-output -d 'Print JSON data instead of an ASCII chart'
complete -c pdu -l top-down -d 'Print the tree top-down instead of bottom-up'
complete -c pdu -l align-left -d 'Fill the bars from left to right'
complete -c pdu -l align-right -d 'Set the root of the bars to the right'
complete -c pdu -l no-sort -d 'Preserve order of entries'
complete -c pdu -l silent-errors -d 'Prevent filesystem error messages from appearing in stderr'
complete -c pdu -l progress -d 'Report progress being made at the expense of performance'
Expand Down
2 changes: 1 addition & 1 deletion exports/completion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Register-ArgumentCompleter -Native -CommandName 'pdu' -ScriptBlock {
[CompletionResult]::new('--json-input', 'json-input', [CompletionResultType]::ParameterName, 'Read JSON data from stdin')
[CompletionResult]::new('--json-output', 'json-output', [CompletionResultType]::ParameterName, 'Print JSON data instead of an ASCII chart')
[CompletionResult]::new('--top-down', 'top-down', [CompletionResultType]::ParameterName, 'Print the tree top-down instead of bottom-up')
[CompletionResult]::new('--align-left', 'align-left', [CompletionResultType]::ParameterName, 'Fill the bars from left to right')
[CompletionResult]::new('--align-right', 'align-right', [CompletionResultType]::ParameterName, 'Set the root of the bars to the right')
[CompletionResult]::new('--no-sort', 'no-sort', [CompletionResultType]::ParameterName, 'Preserve order of entries')
[CompletionResult]::new('--silent-errors', 'silent-errors', [CompletionResultType]::ParameterName, 'Prevent filesystem error messages from appearing in stderr')
[CompletionResult]::new('--progress', 'progress', [CompletionResultType]::ParameterName, 'Report progress being made at the expense of performance')
Expand Down
2 changes: 1 addition & 1 deletion exports/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ block-count\:"Count numbers of blocks"))' \
'(--quantity)--json-input[Read JSON data from stdin]' \
'--json-output[Print JSON data instead of an ASCII chart]' \
'--top-down[Print the tree top-down instead of bottom-up]' \
'--align-left[Fill the bars from left to right]' \
'--align-right[Set the root of the bars to the right]' \
'--no-sort[Preserve order of entries]' \
'--silent-errors[Prevent filesystem error messages from appearing in stderr]' \
'--progress[Report progress being made at the expense of performance]' \
Expand Down
8 changes: 4 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ impl App {
let Args {
bytes_format,
top_down,
align_left,
align_right,
max_depth,
..
} = self.args;
let direction = Direction::from_top_down(top_down);
let bar_alignment = BarAlignment::from_align_left(align_left);
let bar_alignment = BarAlignment::from_align_right(align_right);

let unit_and_tree = stdin()
.pipe(serde_json::from_reader::<_, JsonData>)
Expand Down Expand Up @@ -132,7 +132,7 @@ impl App {
json_output,
bytes_format,
top_down,
align_left,
align_right,
max_depth,
min_ratio,
no_sort,
Expand All @@ -141,7 +141,7 @@ impl App {
{
return Sub {
direction: Direction::from_top_down(top_down),
bar_alignment: BarAlignment::from_align_left(align_left),
bar_alignment: BarAlignment::from_align_right(align_right),
get_data: $get_data,
reporter: $create_reporter::<$data>(report_error),
bytes_format: $format(bytes_format),
Expand Down
4 changes: 2 additions & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ pub struct Args {
#[clap(long)]
pub top_down: bool,

/// Fill the bars from left to right.
/// Set the root of the bars to the right.
#[clap(long)]
pub align_left: bool,
pub align_right: bool,

/// Aspect of the files/directories to be measured.
#[clap(long, value_enum, default_value_t = Quantity::DEFAULT)]
Expand Down
8 changes: 4 additions & 4 deletions src/visualizer/bar_alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pub enum BarAlignment {

impl BarAlignment {
#[cfg(feature = "cli")]
pub(crate) const fn from_align_left(align_left: bool) -> Self {
if align_left {
BarAlignment::Left
} else {
pub(crate) const fn from_align_right(align_right: bool) -> Self {
if align_right {
BarAlignment::Right
} else {
BarAlignment::Left
}
}
}
2 changes: 1 addition & 1 deletion tests/cli_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn fs_errors() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down
2 changes: 1 addition & 1 deletion tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn json_input() {
data_tree: &sample_tree(),
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down
36 changes: 18 additions & 18 deletions tests/usual_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn total_width() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -90,7 +90,7 @@ fn column_width() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::components(10, 90),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -127,7 +127,7 @@ fn min_ratio_0() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -165,7 +165,7 @@ fn min_ratio() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -203,7 +203,7 @@ fn max_depth_2() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 2.try_into().unwrap(),
};
Expand Down Expand Up @@ -241,7 +241,7 @@ fn max_depth_1() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 1.try_into().unwrap(),
};
Expand Down Expand Up @@ -278,7 +278,7 @@ fn top_down() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::TopDown,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand All @@ -290,12 +290,12 @@ fn top_down() {
}

#[test]
fn align_left() {
fn align_right() {
let workspace = SampleWorkspace::default();
let actual = Command::new(PDU)
.with_current_dir(workspace.as_path())
.with_arg("--total-width=100")
.with_arg("--align-left")
.with_arg("--align-right")
.pipe(stdio)
.output()
.expect("spawn command")
Expand All @@ -315,7 +315,7 @@ fn align_left() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Left,
bar_alignment: BarAlignment::Right,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -352,7 +352,7 @@ fn quantity_apparent_size() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -390,7 +390,7 @@ fn quantity_block_size() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -428,7 +428,7 @@ fn quantity_block_count() {
data_tree: &data_tree,
bytes_format: (),
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -467,7 +467,7 @@ fn bytes_format_plain() {
data_tree: &data_tree,
bytes_format: BytesFormat::PlainNumber,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -506,7 +506,7 @@ fn bytes_format_metric() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -545,7 +545,7 @@ fn bytes_format_binary() {
data_tree: &data_tree,
bytes_format: BytesFormat::BinaryUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -581,7 +581,7 @@ fn path_to_workspace() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down Expand Up @@ -633,7 +633,7 @@ fn multiple_names() {
data_tree: &data_tree,
bytes_format: BytesFormat::MetricUnits,
direction: Direction::BottomUp,
bar_alignment: BarAlignment::Right,
bar_alignment: BarAlignment::Left,
column_width_distribution: ColumnWidthDistribution::total(100),
max_depth: 10.try_into().unwrap(),
};
Expand Down

0 comments on commit be80dc1

Please sign in to comment.