on 448bfaf help sign in
bat/src/config.rs
114 lines 3.2 kB history raw
1use crate::line_range::{HighlightedLineRanges, LineRanges};
2#[cfg(feature = "paging")]
3use crate::paging::PagingMode;
4use crate::style::StyleComponents;
5use crate::syntax_mapping::SyntaxMapping;
6use crate::wrapping::WrappingMode;
8#[derive(Debug, Clone)]
9pub enum VisibleLines {
10 /// Show all lines which are included in the line ranges
11 Ranges(LineRanges),
13 #[cfg(feature = "git")]
14 /// Only show lines surrounding added/deleted/modified lines
15 DiffContext(usize),
18impl VisibleLines {
19 pub fn diff_mode(&self) -> bool {
20 match self {
21 Self::Ranges(_) => false,
22 #[cfg(feature = "git")]
23 Self::DiffContext(_) => true,
24 }
25 }
28impl Default for VisibleLines {
29 fn default() -> Self {
30 VisibleLines::Ranges(LineRanges::default())
31 }
34#[derive(Debug, Clone, Default)]
35pub struct Config<'a> {
36 /// The explicitly configured language, if any
37 pub language: Option<&'a str>,
39 /// Whether or not to show/replace non-printable characters like space, tab and newline.
40 pub show_nonprintable: bool,
42 /// The character width of the terminal
43 pub term_width: usize,
45 /// The width of tab characters.
46 /// Currently, a value of 0 will cause tabs to be passed through without expanding them.
47 pub tab_width: usize,
49 /// Whether or not to simply loop through all input (`cat` mode)
50 pub loop_through: bool,
52 /// Whether or not the output should be colorized
53 pub colored_output: bool,
55 /// Whether or not the output terminal supports true color
56 pub true_color: bool,
58 /// Style elements (grid, line numbers, ...)
59 pub style_components: StyleComponents,
61 /// If and how text should be wrapped
62 pub wrapping_mode: WrappingMode,
64 /// Pager or STDOUT
65 #[cfg(feature = "paging")]
66 pub paging_mode: PagingMode,
68 /// Specifies which lines should be printed
69 pub visible_lines: VisibleLines,
71 /// The syntax highlighting theme
72 pub theme: String,
74 /// File extension/name mappings
75 pub syntax_mapping: SyntaxMapping<'a>,
77 /// Command to start the pager
78 pub pager: Option<&'a str>,
80 /// Whether or not to use ANSI italics
81 pub use_italic_text: bool,
83 /// Ranges of lines which should be highlighted with a special background color
84 pub highlighted_lines: HighlightedLineRanges,
86 /// Whether or not to allow custom assets. If this is false or if custom assets (a.k.a.
87 /// cached assets) are not available, assets from the binary will be used instead.
88 pub use_custom_assets: bool,
91#[cfg(all(feature = "minimal-application", feature = "paging"))]
92pub fn get_pager_executable(config_pager: Option<&str>) -> Option<String> {
93 crate::pager::get_pager(config_pager)
94 .ok()
95 .flatten()
96 .map(|pager| pager.bin)
99#[test]
100fn default_config_should_include_all_lines() {
101 use crate::line_range::RangeCheckResult;
103 assert_eq!(LineRanges::default().check(17), RangeCheckResult::InRange);
106#[test]
107fn default_config_should_highlight_no_lines() {
108 use crate::line_range::RangeCheckResult;
110 assert_ne!(
111 Config::default().highlighted_lines.0.check(17),
112 RangeCheckResult::InRange
113 );