@@ -2,8 +2,13 @@ use std::ffi::OsStr;
22use std::io::Read;
33
44use crate::{
5− assets::HighlightingAssets, config::Config, controller::Controller, errors::Result,
6− input::Input, HighlightedLineRanges, LineRanges, StyleComponents, SyntaxMapping, WrappingMode,
5+ assets::HighlightingAssets,
6+ config::Config,
7+ controller::Controller,
8+ errors::Result,
9+ input::Input,
10+ line_range::{HighlightedLineRanges, LineRanges},
11+ LineRange, StyleComponents, SyntaxMapping, WrappingMode,
712};
813
914#[cfg(feature = "paging")]
@@ -13,6 +18,8 @@ pub struct PrettyPrinter<'a> {
1318 inputs: Vec<Input<'a>>,
1419 config: Config<'a>,
1520 assets: HighlightingAssets,
21+
22+ highlighted_lines: Vec<LineRange>,
1623}
1724
1825impl<'a> PrettyPrinter<'a> {
@@ -26,6 +33,7 @@ impl<'a> PrettyPrinter<'a> {
2633 inputs: vec![],
2734 config,
2835 assets: HighlightingAssets::from_binary(),
36+ highlighted_lines: vec![],
2937 }
3038 }
3139
@@ -132,9 +140,11 @@ impl<'a> PrettyPrinter<'a> {
132140 self
133141 }
134142
135− /// Specify which lines should be highlighted (default: none)
136− pub fn highlighted_lines(&mut self, ranges: HighlightedLineRanges) -> &mut Self {
137− self.config.highlighted_lines = ranges;
143+ /// Specify a range of lines that should be highlighted (default: none).
144+ /// This can be called multiple times to highlight more than one range
145+ /// of lines.
146+ pub fn highlight(&mut self, range: LineRange) -> &mut Self {
147+ self.highlighted_lines.push(range);
138148 self
139149 }
140150
@@ -154,6 +164,9 @@ impl<'a> PrettyPrinter<'a> {
154164 /// If you want to call 'run' multiple times, you have to call the appropriate
155165 /// input_* methods again.
156166 pub fn run(&mut self) -> Result<bool> {
167+ self.config.highlighted_lines =
168+ HighlightedLineRanges(LineRanges::from(self.highlighted_lines.clone()));
169+
157170 let mut inputs: Vec<Input> = vec![];
158171 std::mem::swap(&mut inputs, &mut self.inputs);
159172