Clear `highlighted_lines` when calling `PrettyPrinter::print`

This commit is contained in:
rhysd 2022-09-05 21:17:08 +09:00
parent abd69f2deb
commit 3d7817d662
1 changed files with 2 additions and 10 deletions

View File

@ -229,14 +229,6 @@ impl<'a> PrettyPrinter<'a> {
self
}
/// Clear highlighted lines added by [`PrettyPrinter::highlight`] and
/// [`PrettyPrinter::highlight_range`]. This is useful when reusing a
/// `PrettyPrinter` instance for multiple different ranges.
pub fn clear_highlights(&mut self) -> &mut Self {
self.highlighted_lines.clear();
self
}
/// Specify the highlighting theme
pub fn theme(&mut self, theme: impl AsRef<str>) -> &mut Self {
self.config.theme = theme.as_ref().to_owned();
@ -271,8 +263,8 @@ impl<'a> PrettyPrinter<'a> {
/// If you want to call 'print' multiple times, you have to call the appropriate
/// input_* methods again.
pub fn print(&mut self) -> Result<bool> {
self.config.highlighted_lines =
HighlightedLineRanges(LineRanges::from(self.highlighted_lines.clone()));
let highlight_lines = std::mem::take(&mut self.highlighted_lines);
self.config.highlighted_lines = HighlightedLineRanges(LineRanges::from(highlight_lines));
self.config.term_width = self
.term_width
.unwrap_or_else(|| Term::stdout().size().1 as usize);