if let Some(columns_short) = m.checked_sub(s.width()) {
let padding_width = c
.width()
.filter(|n| *n > 0)
.expect("padding character should be visible");
// Saturate the columns_short
let padding_needed = columns_short + padding_width - 1 / padding_width;
let mut t = String::with_capacity(s.len() + padding_needed);
t.extend((0..padding_needed).map(|_| c)
t.push_str(&s);
s = t;
}
This uses the Unicode display width to determine the padding needed. This will be appropriate for most uses of monospaced text.
It assumes that m won't combine with other characters to form a grapheme.
It assumes that m won't combine with other characters to form a grapheme.