on 5f6e310 help sign in
bat/src/config.rs
97 lines 2.6 kB history raw
1pub use crate::inputfile::InputFile;
2pub use crate::inputfile::OrdinaryFile;
3pub use crate::line_range::{HighlightedLineRanges, LineRange, LineRanges};
4pub use crate::style::{StyleComponent, StyleComponents};
5pub use crate::syntax_mapping::{MappingTarget, SyntaxMapping};
6pub use crate::wrap::OutputWrap;
8#[derive(Debug, Clone, Copy, PartialEq)]
9#[cfg(feature = "paging")]
10pub enum PagingMode {
11 Always,
12 QuitIfOneScreen,
13 Never,
16#[cfg(feature = "paging")]
17impl Default for PagingMode {
18 fn default() -> Self {
19 PagingMode::Never
20 }
23#[derive(Debug, Clone, Default)]
24pub struct Config<'a> {
25 /// List of files to print
26 pub files: Vec<InputFile<'a>>,
28 /// The explicitly configured language, if any
29 pub language: Option<&'a str>,
31 /// Whether or not to show/replace non-printable characters like space, tab and newline.
32 pub show_nonprintable: bool,
34 /// The character width of the terminal
35 pub term_width: usize,
37 /// The width of tab characters.
38 /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
39 pub tab_width: usize,
41 /// Whether or not to simply loop through all input (`cat` mode)
42 pub loop_through: bool,
44 /// Whether or not the output should be colorized
45 pub colored_output: bool,
47 /// Whether or not the output terminal supports true color
48 pub true_color: bool,
50 /// Style elements (grid, line numbers, ...)
51 pub style_components: StyleComponents,
53 /// Text wrapping mode
54 pub output_wrap: OutputWrap,
56 /// Pager or STDOUT
57 #[cfg(feature = "paging")]
58 pub paging_mode: PagingMode,
60 /// Specifies the lines that should be printed
61 pub line_ranges: LineRanges,
63 /// The syntax highlighting theme
64 pub theme: String,
66 /// File extension/name mappings
67 pub syntax_mapping: SyntaxMapping<'a>,
69 /// Command to start the pager
70 pub pager: Option<&'a str>,
72 /// Whether or not to use ANSI italics
73 pub use_italic_text: bool,
75 /// Ranges of lines which should be highlighted with a special background color
76 pub highlighted_lines: HighlightedLineRanges,
79#[test]
80fn default_config_should_include_all_lines() {
81 use crate::line_range::RangeCheckResult;
83 assert_eq!(
84 Config::default().line_ranges.check(17),
85 RangeCheckResult::InRange
86 );
89#[test]
90fn default_config_should_highlight_no_lines() {
91 use crate::line_range::RangeCheckResult;
93 assert_ne!(
94 Config::default().highlighted_lines.0.check(17),
95 RangeCheckResult::InRange
96 );