|
|
|
@ -29,11 +29,13 @@ use crate::diff::LineChanges;
|
|
|
|
|
use crate::error::*;
|
|
|
|
|
use crate::input::OpenedInput;
|
|
|
|
|
use crate::line_range::RangeCheckResult;
|
|
|
|
|
use crate::preprocessor::strip_ansi;
|
|
|
|
|
use crate::preprocessor::{expand_tabs, replace_nonprintable};
|
|
|
|
|
use crate::style::StyleComponent;
|
|
|
|
|
use crate::terminal::{as_terminal_escaped, to_ansi_color};
|
|
|
|
|
use crate::vscreen::{AnsiStyle, EscapeSequence, EscapeSequenceIterator};
|
|
|
|
|
use crate::wrapping::WrappingMode;
|
|
|
|
|
use crate::StripAnsiMode;
|
|
|
|
|
|
|
|
|
|
const ANSI_UNDERLINE_ENABLE: EscapeSequence = EscapeSequence::CSI {
|
|
|
|
|
raw_sequence: "\x1B[4m",
|
|
|
|
@ -207,6 +209,7 @@ pub(crate) struct InteractivePrinter<'a> {
|
|
|
|
|
highlighter_from_set: Option<HighlighterFromSet<'a>>,
|
|
|
|
|
background_color_highlight: Option<Color>,
|
|
|
|
|
consecutive_empty_lines: usize,
|
|
|
|
|
strip_ansi: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> InteractivePrinter<'a> {
|
|
|
|
@ -281,6 +284,13 @@ impl<'a> InteractivePrinter<'a> {
|
|
|
|
|
Some(HighlighterFromSet::new(syntax_in_set, theme))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Determine when to strip ANSI sequences
|
|
|
|
|
let strip_ansi = match config.strip_ansi {
|
|
|
|
|
_ if config.show_nonprintable => false,
|
|
|
|
|
StripAnsiMode::Always => true,
|
|
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Ok(InteractivePrinter {
|
|
|
|
|
panel_width,
|
|
|
|
|
colors,
|
|
|
|
@ -293,6 +303,7 @@ impl<'a> InteractivePrinter<'a> {
|
|
|
|
|
highlighter_from_set,
|
|
|
|
|
background_color_highlight,
|
|
|
|
|
consecutive_empty_lines: 0,
|
|
|
|
|
strip_ansi,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -573,7 +584,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|
|
|
|
)
|
|
|
|
|
.into()
|
|
|
|
|
} else {
|
|
|
|
|
match self.content_type {
|
|
|
|
|
let mut line = match self.content_type {
|
|
|
|
|
Some(ContentType::BINARY) | None => {
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
@ -590,7 +601,14 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|
|
|
|
line
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// If ANSI escape sequences are supposed to be stripped, do it before syntax highlighting.
|
|
|
|
|
if self.strip_ansi {
|
|
|
|
|
line = strip_ansi(&line).into()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
line
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let regions = self.highlight_regions_for_line(&line)?;
|
|
|
|
|