mirror of
https://github.com/sharkdp/bat.git
synced 2025-03-20 01:28:49 +00:00
Added non-interactive mode for --list-languages
This makes scripting it a lot easier and less hacky.
This commit is contained in:
parent
27e0ca98d9
commit
493a4e719e
12
src/main.rs
12
src/main.rs
@ -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(())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user