on 522ab7a help sign in
bat/src/config.rs
96 lines 2.5 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)]
8pub enum PagingMode {
9 Always,
10 QuitIfOneScreen,
11 Never,
14impl Default for PagingMode {
15 fn default() -> Self {
16 PagingMode::Never
17 }
20#[derive(Debug, Clone, Default)]
21pub struct Config<'a> {
22 /// List of files to print
23 pub files: Vec<InputFile<'a>>,
25 /// The explicitly configured language, if any
26 pub language: Option<&'a str>,
28 /// Whether or not to show/replace non-printable characters like space, tab and newline.
29 pub show_nonprintable: bool,
31 /// The character width of the terminal
32 pub term_width: usize,
34 /// The width of tab characters.
35 /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
36 pub tab_width: usize,
38 /// Whether or not to simply loop through all input (`cat` mode)
39 pub loop_through: bool,
41 /// Whether or not the output should be colorized
42 pub colored_output: bool,
44 /// Whether or not the output terminal supports true color
45 pub true_color: bool,
47 /// Style elements (grid, line numbers, ...)
48 pub style_components: StyleComponents,
50 /// Text wrapping mode
51 pub output_wrap: OutputWrap,
53 /// Pager or STDOUT
54 pub paging_mode: PagingMode,
56 /// Specifies the lines that should be printed
57 pub line_ranges: LineRanges,
59 /// The syntax highlighting theme
60 pub theme: String,
62 /// File extension/name mappings
63 pub syntax_mapping: SyntaxMapping<'a>,
65 /// Command to start the pager
66 pub pager: Option<&'a str>,
68 /// Whether or not to use ANSI italics
69 pub use_italic_text: bool,
71 /// Ranges of lines which should be highlighted with a special background color
72 pub highlighted_lines: HighlightedLineRanges,
74 /// Names of files to display when printing
75 pub filenames: Option<Vec<&'a str>>,
78#[test]
79fn default_config_should_include_all_lines() {
80 use crate::line_range::RangeCheckResult;
82 assert_eq!(
83 Config::default().line_ranges.check(17),
84 RangeCheckResult::InRange
85 );
88#[test]
89fn default_config_should_highlight_no_lines() {
90 use crate::line_range::RangeCheckResult;
92 assert_ne!(
93 Config::default().highlighted_lines.0.check(17),
94 RangeCheckResult::InRange
95 );