FmtSpec
Stores reusable formatting options.
FmtSpec values are immutable. Calling one returns a new specification with
the supplied options overridden, or a bound FmtValue when
given a positional value.
Inherits from: Func
Constructor
FmtSpec …
Creates a specification from formatting options.
Parameters
| Name | Type | Description |
|---|---|---|
:fill? |
FmtFill |
Padding fill |
:align? |
FmtAlign |
Alignment |
:sign? |
FmtSign |
Sign display |
:width? |
Int |
Minimum width in grapheme clusters |
:precision? |
Int |
Numeric precision or maximum graphemes |
:alt? |
Bool |
Enables alternate formatting |
:kind? |
FmtKind |
Representation kind |
Example
Fields
align @ (FmtAlign | nil)[get]:LEFT:,:RIGHT:,:CENTER:, or nil for the formatted value's default.alt @ Bool[get]Whether alternate formatting is enabled.
fill @ (FmtFill | nil)[get]The fill character,
:ZERO:for numeric zero padding, or nil for spaces.kind @ (FmtKind | nil)[get]The requested representation, or nil to inherit the surrounding conversion.
Kind Representation Conversion :STR:string s:DBG:debug ?:VERBATIM:verbatim !:HEX:integer (hex) x:OCT:integer (octal) o:BIN:integer (binary) b:DEC:integer (decimal) d:EXP:float (scientific) e:FIXED:float (fixed) fThe Conversion column gives the equivalent character in a formatted interpolation.
precision @ (Int | nil)[get]The numeric precision or maximum number of extended grapheme clusters, depending on the formatted value, or nil when unset.
sign @ (FmtSign | nil)[get]:PLUS:,:SPACE:, or nil to show only negative signs.width @ (Int | nil)[get]The minimum width in extended grapheme clusters, or nil when unset. A value may measure itself differently:
term.Textmeasures terminal cells.
Methods
(call) … -> FmtSpec overload 1 of 2
Returns a new specification, or a bound FmtValue when
value is provided. Omitted options retain their current values; nil resets
an option.
Binding a FmtValue nests it: the inner specification
renders the value and this one lays that rendering out. See
Sequencing.
Parameters
| Name | Type | Description |
|---|---|---|
:fill? |
(FmtFill | nil) |
Padding fill |
:align? |
(FmtAlign | nil) |
Alignment |
:sign? |
(FmtSign | nil) |
Sign display |
:width? |
(Int | nil) |
Minimum width in grapheme clusters |
:precision? |
(Int | nil) |
Numeric precision or maximum graphemes |
:alt? |
(Bool | nil) |
Enables alternate formatting |
:kind? |
(FmtKind | nil) |
Representation kind |
pad value -> Str
Applies fill, alignment, width, and truncation to a string.
Parameters
| Name | Type | Description |
|---|---|---|
value |
Str |
String to lay out |