Kite

fmt

std/fmt — laying text out in columns.

There is no format-string language in Kite, and there is not going to be one: \(x) interpolation calls Display.show and has no injection surface and nothing to learn. What interpolation cannot do is align things, which is what this module is for.

pad

pub fn pad(s: str, width: int) -> str

s at least width characters wide, padded on the right.

pad_left

pub fn pad_left(s: str, width: int) -> str

s at least width characters wide, padded on the left.

centre

pub fn centre(s: str, width: int) -> str

s centred in width, with any odd space going to the right.

ellipsis

pub fn ellipsis(s: str, width: int) -> str

s cut to width, with an ellipsis when something was cut.

fixed

pub fn fixed(x: float, places: int) -> str

A float with exactly places digits after the point.

Rounds the float's own value half away from zero, which is what most people mean. Every place asked for is a digit of that value, past the seventeenth significant one too, so the answer is %.Nf's except at an exact half, which %.Nf rounds to even. The float written 2.005 is 2.00499999999999989…, so it gives 2.00, as 1.005 gives 1.00; 2.125 is exactly that and gives 2.13.

Worked out in integers from the float's exact decimal expansion rather than by scaling it, for two reasons. The result does not depend on how the host prints a float, which the backends do not agree about past about 1e21. And a scaled float is rounded before it is split into whole and fraction: 1000000000000000.25 scaled by 100 is already 100000000000000032, 0.49999999999999994 + 0.5 is already 1, and an int cannot hold the scaled value of fixed(1e20, 2) at all.

A negative number keeps its sign when it rounds to zero, -0.00, and so does -0.0 itself, as %.Nf writes both. JavaScript's toFixed writes -0 for the one and 0 for the other.

An infinity is written inf or -inf, and a NaN nan.

percent

pub fn percent(part: float, whole: float) -> str

A percentage, to one decimal place.

grouped

pub fn grouped(n: int) -> str

An integer with thousands separators.

row

pub fn row(cells: [str], widths: [int]) -> str

A row of columns, each padded to its width.