summaryrefslogtreecommitdiffstats
path: root/src/printer.rs
diff options
context:
space:
mode:
authorEthan P. <eth-p+git@hidden.email>2024-02-11 22:29:25 -0800
committerEthan P. <eth-p+git@hidden.email>2024-02-11 22:49:49 -0800
commit25b5a4118939a489a746feb6116f709584d08ab3 (patch)
treecab8988cf90d5d268095fe697a993fd502563664 /src/printer.rs
parentc94cf4e14e672a5bb169d9747c744a9b992c53b8 (diff)
Skip syntax parsing when color output disabled
Diffstat (limited to 'src/printer.rs')
-rw-r--r--src/printer.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/printer.rs b/src/printer.rs
index 3ac850fa..8fd6bc8e 100644
--- a/src/printer.rs
+++ b/src/printer.rs
@@ -9,6 +9,7 @@ use bytesize::ByteSize;
use syntect::easy::HighlightLines;
use syntect::highlighting::Color;
+use syntect::highlighting::FontStyle;
use syntect::highlighting::Theme;
use syntect::parsing::SyntaxSet;
@@ -48,6 +49,22 @@ const ANSI_UNDERLINE_DISABLE: EscapeSequence = EscapeSequence::CSI {
final_byte: "m",
};
+const EMPTY_SYNTECT_STYLE: syntect::highlighting::Style = syntect::highlighting::Style {
+ foreground: Color {
+ r: 127,
+ g: 127,
+ b: 127,
+ a: 255,
+ },
+ background: Color {
+ r: 127,
+ g: 127,
+ b: 127,
+ a: 255,
+ },
+ font_style: FontStyle::empty(),
+};
+
pub enum OutputHandle<'a> {
IoWrite(&'a mut dyn io::Write),
FmtWrite(&'a mut dyn fmt::Write),
@@ -222,11 +239,13 @@ impl<'a> InteractivePrinter<'a> {
panel_width = 0;
}
- let highlighter_from_set = if input
+ // Get the highlighter for the output.
+ let is_printing_binary = input
.reader
.content_type
- .map_or(false, |c| c.is_binary() && !config.show_nonprintable)
- {
+ .map_or(false, |c| c.is_binary() && !config.show_nonprintable);
+
+ let highlighter_from_set = if is_printing_binary || config.colored_output == false {
None
} else {
// Determine the type of syntax for highlighting