|
|
|
@ -268,26 +268,40 @@ impl<'a> InteractivePrinter<'a> {
|
|
|
|
|
.content_type
|
|
|
|
|
.map_or(false, |c| c.is_binary() && !config.show_nonprintable);
|
|
|
|
|
|
|
|
|
|
let highlighter_from_set = if is_printing_binary || !config.colored_output {
|
|
|
|
|
None
|
|
|
|
|
} else {
|
|
|
|
|
let needs_to_match_syntax = !is_printing_binary
|
|
|
|
|
&& (config.colored_output || config.strip_ansi == StripAnsiMode::Auto);
|
|
|
|
|
|
|
|
|
|
let (is_plain_text, highlighter_from_set) = if needs_to_match_syntax {
|
|
|
|
|
// Determine the type of syntax for highlighting
|
|
|
|
|
let syntax_in_set =
|
|
|
|
|
const PLAIN_TEXT_SYNTAX: &str = "Plain Text";
|
|
|
|
|
match assets.get_syntax(config.language, input, &config.syntax_mapping) {
|
|
|
|
|
Ok(syntax_in_set) => syntax_in_set,
|
|
|
|
|
Err(Error::UndetectedSyntax(_)) => assets
|
|
|
|
|
.find_syntax_by_name("Plain Text")?
|
|
|
|
|
Ok(syntax_in_set) => (
|
|
|
|
|
syntax_in_set.syntax.name == PLAIN_TEXT_SYNTAX,
|
|
|
|
|
Some(HighlighterFromSet::new(syntax_in_set, theme)),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
Err(Error::UndetectedSyntax(_)) => (
|
|
|
|
|
true,
|
|
|
|
|
Some(
|
|
|
|
|
assets
|
|
|
|
|
.find_syntax_by_name(PLAIN_TEXT_SYNTAX)?
|
|
|
|
|
.map(|s| HighlighterFromSet::new(s, theme))
|
|
|
|
|
.expect("A plain text syntax is available"),
|
|
|
|
|
Err(e) => return Err(e),
|
|
|
|
|
};
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
Some(HighlighterFromSet::new(syntax_in_set, theme))
|
|
|
|
|
Err(e) => return Err(e),
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
(false, None)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Determine when to strip ANSI sequences
|
|
|
|
|
let strip_ansi = match config.strip_ansi {
|
|
|
|
|
_ if config.show_nonprintable => false,
|
|
|
|
|
StripAnsiMode::Always => true,
|
|
|
|
|
StripAnsiMode::Auto if is_plain_text => false, // Plain text may already contain escape sequences.
|
|
|
|
|
StripAnsiMode::Auto => true,
|
|
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|