diff options
author | sharkdp <davidpeter@web.de> | 2020-04-22 22:50:57 +0200 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2020-04-22 23:55:28 +0200 |
commit | 17f3a3b95da60b27fcd341b0a47a76aaa2784bc5 (patch) | |
tree | 4e5a03f11c5c0e871ae7a22ee2093e33e782cc0b | |
parent | 261a7ea1549cbcd01986f891bbaf1b5936e7641d (diff) |
Simpler highlight method
-rw-r--r-- | examples/advanced.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/pretty_printer.rs | 16 |
3 files changed, 14 insertions, 7 deletions
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) @@ -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 } |