Fix padding (#822)

This commit is contained in:
Denis Isidoro 2023-04-08 21:15:55 -03:00 committed by GitHub
parent f6414551bb
commit 4f63f30ed7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,11 +34,11 @@ fn limit_str(text: &str, length: usize) -> String {
let mut new_length = length;
let mut actual_length = 9999;
let mut txt = text.to_owned();
while actual_length > length {
while actual_length >= length {
txt = txt.chars().take(new_length - 1).collect::<String>();
actual_length = UnicodeWidthStr::width(txt.as_str());
new_length -= 1;
}
format!("{}", txt)
format!("{}{}", txt, " ".repeat(length - actual_length - 1))
}
}