From 4c60ab12ccf546f6f8269c3dcf11398f094b800b Mon Sep 17 00:00:00 2001 From: Connor Kuehl Date: Mon, 7 May 2018 14:42:58 -0700 Subject: [PATCH] Add simple line-wrapping for file extensions. --- src/main.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index cdd4817a..472d04db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(());