on master help sign in
Add advanced example
commit74d4377ed28c4350807c967597ba5081f2ce7a74 authorsharkdp <davidpeter@web.de> dateWed 22 Apr 2020, 21:16 (7 years ago) parent6a12459
1 file changed+20
examples/advanced.rs+20
examples/advanced.rsnew file+20
@@ -0,0 +1,20 @@
1+/// A program that prints its own source code using the bat library
2+use bat::{LineRange, PrettyPrinter, WrappingMode};
3+use std::ffi::OsStr;
4+
5+fn main() {
6+ let path_to_this_file = OsStr::new(file!());
7+
8+ PrettyPrinter::new()
9+ .header(true)
10+ .grid(true)
11+ .line_numbers(true)
12+ .use_italics(true)
13+ // The following line will be highlighted in the output:
14+ .highlight(LineRange::new(line!() as usize, line!() as usize))
15+ .theme("1337")
16+ .wrapping_mode(WrappingMode::Character)
17+ .input_file(path_to_this_file)
18+ .print()
19+ .expect("no errors");
20+}