on 47a3721 help sign in
bat/src/config.rs
99 lines 2.6 kB history raw
1pub use crate::inputfile::InputFile;
2pub use crate::line_range::{HighlightedLineRanges, LineRange, LineRanges};
3pub use crate::style::{StyleComponent, StyleComponents};
4pub use crate::syntax_mapping::{MappingTarget, SyntaxMapping};
5pub use crate::wrap::OutputWrap;
7#[derive(Debug, Clone, Copy, PartialEq)]
8#[cfg(feature = "paging")]
9pub enum PagingMode {
10 Always,
11 QuitIfOneScreen,
12 Never,
15#[cfg(feature = "paging")]
16impl Default for PagingMode {
17 fn default() -> Self {
18 PagingMode::Never
19 }
22#[derive(Debug, Clone, Default)]
23pub struct Config<'a> {
24 /// List of files to print
25 pub files: Vec<InputFile<'a>>,
27 /// The explicitly configured language, if any
28 pub language: Option<&'a str>,
30 /// Whether or not to show/replace non-printable characters like space, tab and newline.
31 pub show_nonprintable: bool,
33 /// The character width of the terminal
34 pub term_width: usize,
36 /// The width of tab characters.
37 /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
38 pub tab_width: usize,
40 /// Whether or not to simply loop through all input (`cat` mode)
41 pub loop_through: bool,
43 /// Whether or not the output should be colorized
44 pub colored_output: bool,
46 /// Whether or not the output terminal supports true color
47 pub true_color: bool,
49 /// Style elements (grid, line numbers, ...)
50 pub style_components: StyleComponents,
52 /// Text wrapping mode
53 pub output_wrap: OutputWrap,
55 /// Pager or STDOUT
56 #[cfg(feature = "paging")]
57 pub paging_mode: PagingMode,
59 /// Specifies the lines that should be printed
60 pub line_ranges: LineRanges,
62 /// The syntax highlighting theme
63 pub theme: String,
65 /// File extension/name mappings
66 pub syntax_mapping: SyntaxMapping<'a>,
68 /// Command to start the pager
69 pub pager: Option<&'a str>,
71 /// Whether or not to use ANSI italics
72 pub use_italic_text: bool,
74 /// Ranges of lines which should be highlighted with a special background color
75 pub highlighted_lines: HighlightedLineRanges,
77 /// Names of files to display when printing
78 pub filenames: Option<Vec<&'a str>>,
81#[test]
82fn default_config_should_include_all_lines() {
83 use crate::line_range::RangeCheckResult;
85 assert_eq!(
86 Config::default().line_ranges.check(17),
87 RangeCheckResult::InRange
88 );
91#[test]
92fn default_config_should_highlight_no_lines() {
93 use crate::line_range::RangeCheckResult;
95 assert_ne!(
96 Config::default().highlighted_lines.0.check(17),
97 RangeCheckResult::InRange
98 );