summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsharkdp <davidpeter@web.de>2020-04-22 22:50:57 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2020-04-22 23:55:28 +0200
commit17f3a3b95da60b27fcd341b0a47a76aaa2784bc5 (patch)
tree4e5a03f11c5c0e871ae7a22ee2093e33e782cc0b
parent261a7ea1549cbcd01986f891bbaf1b5936e7641d (diff)
Simpler highlight method
-rw-r--r--examples/advanced.rs4
-rw-r--r--src/lib.rs1
-rw-r--r--src/pretty_printer.rs16
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)
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
}