feat(format): expand pow_format modifiers
Extend the pow_format spec parser beyond alignment so configs can shape the
rendered number, not just pad it. A forced scale (#, k, M, G, T, P) pins the SI
prefix instead of auto-selecting it and, since the author then knows both scale
and unit, hides the prefix and unit by default; U brings the unit back, u hides
it in auto mode, and i forces integer display. b and B override the decimal or
binary base independently of the call site, and a trailing width now fixes the
coefficient field when a scale is forced, overflowing to '#' when it does not
fit.
The old '>' and '<' branches rendered via fmt::format("{}", s), which discarded
every new field on the recursive call; they now build from a single render path
that reads the current formatter, so modifiers survive alignment. The auto path
is byte-identical to before, verified against the previous implementation.
Adds a Catch2 suite covering each modifier alone and combined, plus the
backward-compatible alignment cases, and documents the modifiers in the network
and disk man pages.
This commit is contained in:
@@ -214,6 +214,34 @@ Addressed by *network*
|
||||
|
||||
*{icon}*: Icon, as defined in *format-icons*.
|
||||
|
||||
# NUMBER FORMAT MODIFIERS
|
||||
|
||||
The bandwidth/bitrate replacements above (*{bandwidth\*}*, *{txBitrate}*,
|
||||
*{rxBitrate}*, *{linkSpeed}*) auto-scale the number with an SI prefix (k, M, G,
|
||||
…). Their rendering can be tuned with fmt-style modifiers, e.g.
|
||||
*"{bandwidthDownBits:>}"* or *"{bandwidthDownBits:M}"*. Modifiers may be combined
|
||||
in any order:
|
||||
|
||||
*<*, *=*, *>*: Alignment/padding (left, column-align, right) — as before.
|
||||
|
||||
*u* / *U*: Hide (*u*) or show (*U*) the unit suffix. The unit is shown by default
|
||||
with an auto scale and hidden by default when a scale is forced (see below).
|
||||
|
||||
*#*, *k*, *M*, *G*, *T*, *P*: Force a fixed scale instead of auto-selecting one
|
||||
(*#* = base scale, no prefix). Forcing a scale hides the scale prefix and, by
|
||||
default, the unit (re-enable it with *U*). E.g. *"{bandwidthDownBits:M}"* always
|
||||
shows the value in megabits.
|
||||
|
||||
*i*: Force integer display (no decimals).
|
||||
|
||||
*b* / *B*: Force decimal base 1000 (*b*) or binary base 1024 with an *i* marker
|
||||
(*B*), overriding the module default.
|
||||
|
||||
A trailing number is a fixed width for the coefficient when a scale is forced; if
|
||||
the value does not fit, it is shown as *#* characters (e.g. *"{bandwidthDownBits:=3#}"*
|
||||
→ *###*). Without a forced scale the number is ignored (kept for config
|
||||
compatibility).
|
||||
|
||||
# EXAMPLES
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user