Skip to content

--summary human sizes: align number/suffix columns + --summary-precision - #235

Merged
helly25 merged 1 commit into
mainfrom
feat/summary-aligned-size
Jul 4, 2026
Merged

--summary human sizes: align number/suffix columns + --summary-precision#235
helly25 merged 1 commit into
mainfrom
feat/summary-aligned-size

Conversation

@helly25

@helly25 helly25 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

The --summary human size column right-aligned each N.N XiB string as a whole, so units were ragged and decimal points didn't line up. This splits the size into two aligned columns.

Before

log    1  2.4 MiB
md     1      2 B
txt    2  1.5 KiB
total  4  2.4 MiB

After (numbers right-aligned with a fixed fraction area so points line up; suffixes left-aligned, all starting at one column; exact bytes render as the integer with the fraction columns blanked)

log    1  2.38 MiB
md     1  2    B
txt    2  1.47 KiB
total  4  2.39 MiB
  • Bytes render as 12 B (integer, fraction area blanked to keep the point aligned), not the 12.00 B "cringe".
  • New --summary-precision=N sets the scaled-unit fraction digits (default 2, matching the 123.45 target; 0 drops the point). --human=off (raw grouped bytes) is unchanged.

format::SizeColumns(bytes, units, fraction_digits) returns the {number, suffix} split (sharing a new ScaleSize with format::Size); the summary renderer pads the number column to its widest cell and appends " " + suffix.

Self-doc: the --summary-precision GlobalFlag (so --help/--man/--markdown pick it up). Tests: format_test (split, byte blanking, zero precision), summary_test (byte spacing + precision control), and the summary_additive golden regenerated. Full bazel test //xff/... green (49); both clang-format versions + shfmt/shellcheck + pre-commit clean.

Note: this makes the aligned layout the default for --summary (the old ragged format is replaced, not kept as a toggle) since --summary is always tabular. Easy to gate behind a flag instead if you'd prefer.

The human size column right-aligned each "N.N XiB" string as a whole, so units were
ragged and decimal points did not line up ("2.4 MiB" over "2 B" over "1.5 KiB"). Split
the size into two columns: a right-aligned number with a fixed fraction area (so points
line up, blanked for exact bytes) and a left-aligned unit suffix that starts at one
column. Bytes render as the integer with the fraction columns blanked (12 B, not the
12.00 B "cringe"), so a byte row still lines up under the scaled rows:

  log    1  2.38 MiB
  md     1  2    B
  txt    2  1.47 KiB
  total  4  2.39 MiB

New --summary-precision=N sets the scaled-unit fraction digits (default 2; 0 drops the
point). --human=off (raw grouped bytes) is unchanged.

format::SizeColumns(bytes, units, fraction_digits) returns the {number, suffix} split
(sharing ScaleSize with format::Size); the summary renderer pads the number column to its
widest cell and appends " " + suffix. Self-doc: the --summary-precision GlobalFlag; --help
/ --man / --markdown regenerate. Tests: format_test (SizeColumns split, byte blanking,
zero precision), summary_test (byte spacing, precision control), and the summary golden.
@helly25
helly25 enabled auto-merge (squash) July 4, 2026 08:45
@helly25
helly25 merged commit 50331f7 into main Jul 4, 2026
8 checks passed
@helly25
helly25 deleted the feat/summary-aligned-size branch July 4, 2026 08:51
helly25 added a commit that referenced this pull request Jul 6, 2026
Remove five stale 'to do' bullets that describe already-implemented work,
so TODO.md stops listing done features as open:
- Right align numbers in summary  -> shipped (#202, #235)
- More output control for summary  -> shipped (#86, #203, #275)
- Align outputs like -ls           -> shipped (#205, #206, #207)
- Mimetype support                 -> shipped (#219 -mime)
- File type support                -> shipped (#262 -lang, #89)

Fix the 'Color support' cross-reference that pointed at the removed
'File type support' bullet to name -lang / {lang} / languages.yml directly.
Genuinely-open items (Line count {lines} field, per-file hashes, --sort/-j
CLI test, histograms #81) are untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant