Add simple line-wrapping for file extensions.

This commit is contained in:
Connor Kuehl 2018-05-07 14:42:58 -07:00 committed by David Peter
parent ac32dd17c9
commit 4c60ab12cc

View file

@ -572,9 +572,30 @@ fn run() -> Result<()> {
.max()
.unwrap_or(32); // Fallback width if they have no language definitions.
let separator = " | ";
for lang in languages {
print!("{:width$} | ", lang.name, width = longest);
println!("{}", lang.file_extensions.join(", "));
print!("{:width$}{}", lang.name, separator, width = longest);
// Line-wrapping for the possible file extension overflow.
let desired_width = 48;
// Number of characters on this line so far, wrap before `desired_width`
let mut num_chars = 0;
let mut extension = lang.file_extensions.iter().peekable();
while let Some(word) = extension.next() {
// If we can't fit this word in, then create a line break and align it in.
if word.len() + num_chars >= desired_width {
num_chars = 0;
print!("\n{:width$}{}", "", separator, width = longest);
}
num_chars += word.len();
print!("{}", word);
if extension.peek().is_some() {
print!(", ");
}
}
println!();
}
return Ok(());