Skip to main content

pad_display

Function pad_display 

Source
pub fn pad_display(s: &str, cells: usize) -> String
Expand description

Left-align s in a column exactly cells terminal columns wide.

This is {:<width$} corrected for the fact that Rust pads to a count of chars and a terminal draws in columns. A CJK or emoji character occupies two of them, so a path whose name is eight Chinese characters measures 8 and draws 16 — and under {:<35} every column to its right shifts by eight. Anything wider than the column is truncated rather than allowed to push its neighbours off the edge.