Add simple line-wrapping for file extensions.
@@ -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(());
