From ebdef04c8f9f6f5b1145f11e8d17688890ec3e80 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Tue, 8 May 2018 22:13:37 +0200 Subject: [PATCH] Compute 'longest' for non-hidden languages only --- src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index cc4d998d..fcd19d34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -569,7 +569,9 @@ fn run() -> Result<()> { if app_matches.is_present("list-languages") { let languages = assets.syntax_set.syntaxes(); - let longest = languages.iter() + let longest = languages + .iter() + .filter(|s| !s.hidden) .map(|s| s.name.len()) .max() .unwrap_or(32); // Fallback width if they have no language definitions. @@ -590,12 +592,13 @@ fn run() -> Result<()> { 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 num_chars + word.len() + comma_separator.len() >= desired_width { + let new_chars = word.len() + comma_separator.len(); + if num_chars + new_chars >= desired_width { num_chars = 0; print!("\n{:width$}{}", "", separator, width = longest); } - num_chars += word.len() + comma_separator.len(); + num_chars += new_chars; print!("{}", word); if extension.peek().is_some() { print!("{}", comma_separator);