Added non-interactive mode for --list-languages

This makes scripting it a lot easier and less hacky.
This commit is contained in:
Ethan P 2019-05-10 14:38:48 -07:00 committed by David Peter
parent 27e0ca98d9
commit 493a4e719e

View File

@ -108,6 +108,14 @@ pub fn list_languages(config: &Config) -> Result<()> {
.collect::<Vec<_>>();
languages.sort_by_key(|lang| lang.name.to_uppercase());
let stdout = io::stdout();
let mut stdout = stdout.lock();
if config.loop_through {
for lang in languages {
write!(stdout, "{}:{}\n", lang.name, lang.file_extensions.join(","));
}
} else {
let longest = languages
.iter()
.map(|syntax| syntax.name.len())
@ -119,9 +127,6 @@ pub fn list_languages(config: &Config) -> Result<()> {
// Line-wrapping for the possible file extension overflow.
let desired_width = config.term_width - longest - separator.len();
let stdout = io::stdout();
let mut stdout = stdout.lock();
let style = if config.colored_output {
Green.normal()
} else {
@ -151,6 +156,7 @@ pub fn list_languages(config: &Config) -> Result<()> {
}
writeln!(stdout)?;
}
}
Ok(())
}