mirror of
https://github.com/sharkdp/bat
synced 2024-11-26 13:50:25 +00:00
Simpler highlight method
This commit is contained in:
parent
261a7ea154
commit
17f3a3b95d
3 changed files with 14 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
/// A program that prints its own source code using the bat library
|
/// 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() {
|
fn main() {
|
||||||
PrettyPrinter::new()
|
PrettyPrinter::new()
|
||||||
|
@ -8,7 +8,7 @@ fn main() {
|
||||||
.line_numbers(true)
|
.line_numbers(true)
|
||||||
.use_italics(true)
|
.use_italics(true)
|
||||||
// The following line will be highlighted in the output:
|
// The following line will be highlighted in the output:
|
||||||
.highlight(LineRange::new(line!() as usize, line!() as usize))
|
.highlight(line!() as usize)
|
||||||
.theme("1337")
|
.theme("1337")
|
||||||
.wrapping_mode(WrappingMode::Character)
|
.wrapping_mode(WrappingMode::Character)
|
||||||
.paging_mode(PagingMode::QuitIfOneScreen)
|
.paging_mode(PagingMode::QuitIfOneScreen)
|
||||||
|
|
|
@ -37,7 +37,6 @@ pub(crate) mod syntax_mapping;
|
||||||
mod terminal;
|
mod terminal;
|
||||||
pub(crate) mod wrapping;
|
pub(crate) mod wrapping;
|
||||||
|
|
||||||
pub use line_range::LineRange;
|
|
||||||
pub use pretty_printer::PrettyPrinter;
|
pub use pretty_printer::PrettyPrinter;
|
||||||
pub use syntax_mapping::{MappingTarget, SyntaxMapping};
|
pub use syntax_mapping::{MappingTarget, SyntaxMapping};
|
||||||
pub use wrapping::WrappingMode;
|
pub use wrapping::WrappingMode;
|
||||||
|
|
|
@ -10,9 +10,9 @@ use crate::{
|
||||||
controller::Controller,
|
controller::Controller,
|
||||||
error::Result,
|
error::Result,
|
||||||
input::Input,
|
input::Input,
|
||||||
line_range::{HighlightedLineRanges, LineRanges},
|
line_range::{HighlightedLineRanges, LineRange, LineRanges},
|
||||||
style::{StyleComponent, StyleComponents},
|
style::{StyleComponent, StyleComponents},
|
||||||
LineRange, SyntaxMapping, WrappingMode,
|
SyntaxMapping, WrappingMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "paging")]
|
#[cfg(feature = "paging")]
|
||||||
|
@ -209,11 +209,19 @@ impl<'a> PrettyPrinter<'a> {
|
||||||
self
|
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).
|
/// Specify a range of lines that should be highlighted (default: none).
|
||||||
/// This can be called multiple times to highlight more than one range
|
/// This can be called multiple times to highlight more than one range
|
||||||
/// of lines.
|
/// of lines.
|
||||||
pub fn highlight(&mut self, range: LineRange) -> &mut Self {
|
pub fn highlight_range(&mut self, from: usize, to: usize) -> &mut Self {
|
||||||
self.highlighted_lines.push(range);
|
self.highlighted_lines.push(LineRange::new(from, to));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue