diff --git a/examples/advanced.rs b/examples/advanced.rs index ec9fb59c..f6c2a018 100644 --- a/examples/advanced.rs +++ b/examples/advanced.rs @@ -1,5 +1,5 @@ /// A program that prints its own source code using the bat library -use bat::{LineRange, PagingMode, PrettyPrinter, WrappingMode}; +use bat::{PagingMode, PrettyPrinter, WrappingMode}; fn main() { PrettyPrinter::new() @@ -8,7 +8,7 @@ fn main() { .line_numbers(true) .use_italics(true) // The following line will be highlighted in the output: - .highlight(LineRange::new(line!() as usize, line!() as usize)) + .highlight(line!() as usize) .theme("1337") .wrapping_mode(WrappingMode::Character) .paging_mode(PagingMode::QuitIfOneScreen) diff --git a/src/lib.rs b/src/lib.rs index b7ab1d20..23e010d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,6 @@ pub(crate) mod syntax_mapping; mod terminal; pub(crate) mod wrapping; -pub use line_range::LineRange; pub use pretty_printer::PrettyPrinter; pub use syntax_mapping::{MappingTarget, SyntaxMapping}; pub use wrapping::WrappingMode; diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs index 4370c0d9..e9d566b7 100644 --- a/src/pretty_printer.rs +++ b/src/pretty_printer.rs @@ -10,9 +10,9 @@ use crate::{ controller::Controller, error::Result, input::Input, - line_range::{HighlightedLineRanges, LineRanges}, + line_range::{HighlightedLineRanges, LineRange, LineRanges}, style::{StyleComponent, StyleComponents}, - LineRange, SyntaxMapping, WrappingMode, + SyntaxMapping, WrappingMode, }; #[cfg(feature = "paging")] @@ -209,11 +209,19 @@ impl<'a> PrettyPrinter<'a> { self } + /// Specify a line that should be highlighted (default: none). + /// This can be called multiple times to highlight more than one + /// line. See also: highlight_range. + pub fn highlight(&mut self, line: usize) -> &mut Self { + self.highlighted_lines.push(LineRange::new(line, line)); + self + } + /// Specify a range of lines that should be highlighted (default: none). /// This can be called multiple times to highlight more than one range /// of lines. - pub fn highlight(&mut self, range: LineRange) -> &mut Self { - self.highlighted_lines.push(range); + pub fn highlight_range(&mut self, from: usize, to: usize) -> &mut Self { + self.highlighted_lines.push(LineRange::new(from, to)); self }