Skip to content

Commit

Permalink
Clear highlighted_lines when calling PrettyPrinter::print
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Sep 5, 2022
1 parent abd69f2 commit 3d7817d
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/pretty_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3d7817d

Please sign in to comment.