mirror of
https://github.com/sharkdp/bat.git
synced 2025-04-13 14:20:36 +01:00
Respect color settings for list-themes and list-languages
This commit is contained in:
parent
90c7d0c365
commit
e3c990f11e
38
src/main.rs
38
src/main.rs
@ -87,7 +87,7 @@ fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_languages(assets: &HighlightingAssets, term_width: usize) -> Result<()> {
|
pub fn list_languages(assets: &HighlightingAssets, config: &Config) -> Result<()> {
|
||||||
let mut languages = assets
|
let mut languages = assets
|
||||||
.syntax_set
|
.syntax_set
|
||||||
.syntaxes()
|
.syntaxes()
|
||||||
@ -105,11 +105,17 @@ pub fn list_languages(assets: &HighlightingAssets, term_width: usize) -> Result<
|
|||||||
let comma_separator = ", ";
|
let comma_separator = ", ";
|
||||||
let separator = " ";
|
let separator = " ";
|
||||||
// Line-wrapping for the possible file extension overflow.
|
// Line-wrapping for the possible file extension overflow.
|
||||||
let desired_width = term_width - longest - separator.len();
|
let desired_width = config.term_width - longest - separator.len();
|
||||||
|
|
||||||
let stdout = io::stdout();
|
let stdout = io::stdout();
|
||||||
let mut stdout = stdout.lock();
|
let mut stdout = stdout.lock();
|
||||||
|
|
||||||
|
let style = if config.colored_output {
|
||||||
|
Green.normal()
|
||||||
|
} else {
|
||||||
|
Style::default()
|
||||||
|
};
|
||||||
|
|
||||||
for lang in languages {
|
for lang in languages {
|
||||||
write!(stdout, "{:width$}{}", lang.name, separator, width = longest)?;
|
write!(stdout, "{:width$}{}", lang.name, separator, width = longest)?;
|
||||||
|
|
||||||
@ -126,7 +132,7 @@ pub fn list_languages(assets: &HighlightingAssets, term_width: usize) -> Result<
|
|||||||
}
|
}
|
||||||
|
|
||||||
num_chars += new_chars;
|
num_chars += new_chars;
|
||||||
write!(stdout, "{}", Green.paint(&word[..]))?;
|
write!(stdout, "{}", style.paint(&word[..]))?;
|
||||||
if extension.peek().is_some() {
|
if extension.peek().is_some() {
|
||||||
write!(stdout, "{}", comma_separator)?;
|
write!(stdout, "{}", comma_separator)?;
|
||||||
}
|
}
|
||||||
@ -148,15 +154,21 @@ pub fn list_themes(assets: &HighlightingAssets, cfg: &Config) -> Result<()> {
|
|||||||
let stdout = io::stdout();
|
let stdout = io::stdout();
|
||||||
let mut stdout = stdout.lock();
|
let mut stdout = stdout.lock();
|
||||||
|
|
||||||
for (theme, _) in themes.iter() {
|
if config.colored_output {
|
||||||
writeln!(
|
for (theme, _) in themes.iter() {
|
||||||
stdout,
|
writeln!(
|
||||||
"Theme: {}\n",
|
stdout,
|
||||||
Style::new().bold().paint(theme.to_string())
|
"Theme: {}\n",
|
||||||
)?;
|
Style::new().bold().paint(theme.to_string())
|
||||||
config.theme = theme.to_string();
|
)?;
|
||||||
let _controller = Controller::new(&config, &assets).run();
|
config.theme = theme.to_string();
|
||||||
writeln!(stdout)?;
|
let _controller = Controller::new(&config, &assets).run();
|
||||||
|
writeln!(stdout)?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (theme, _) in themes.iter() {
|
||||||
|
writeln!(stdout, "{}", theme)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -177,7 +189,7 @@ fn run() -> Result<bool> {
|
|||||||
let assets = HighlightingAssets::new();
|
let assets = HighlightingAssets::new();
|
||||||
|
|
||||||
if app.matches.is_present("list-languages") {
|
if app.matches.is_present("list-languages") {
|
||||||
list_languages(&assets, config.term_width)?;
|
list_languages(&assets, &config)?;
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else if app.matches.is_present("list-themes") {
|
} else if app.matches.is_present("list-themes") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user