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;
7
8#[derive(Debug, Clone)]
9pub enum VisibleLines {
10 Ranges(LineRanges),
12
13 #[cfg(feature = "git")]
14 DiffContext(usize),
16}
17
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 }
26}
27
28impl Default for VisibleLines {
29 fn default() -> Self {
30 VisibleLines::Ranges(LineRanges::default())
31 }
32}
33
34#[derive(Debug, Clone, Default)]
35pub struct Config<'a> {
36 pub language: Option<&'a str>,
38
39 pub show_nonprintable: bool,
41
42 pub term_width: usize,
44
45 pub tab_width: usize,
48
49 pub loop_through: bool,
51
52 pub colored_output: bool,
54
55 pub true_color: bool,
57
58 pub style_components: StyleComponents,
60
61 pub wrapping_mode: WrappingMode,
63
64 #[cfg(feature = "paging")]
66 pub paging_mode: PagingMode,
67
68 pub visible_lines: VisibleLines,
70
71 pub theme: String,
73
74 pub syntax_mapping: SyntaxMapping<'a>,
76
77 pub pager: Option<&'a str>,
79
80 pub use_italic_text: bool,
82
83 pub highlighted_lines: HighlightedLineRanges,
85
86 pub use_custom_assets: bool,
89}
90
91#[cfg(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)
97}
98
99#[test]
100fn default_config_should_include_all_lines() {
101 use crate::line_range::RangeCheckResult;
102
103 assert_eq!(LineRanges::default().check(17), RangeCheckResult::InRange);
104}
105
106#[test]
107fn default_config_should_highlight_no_lines() {
108 use crate::line_range::RangeCheckResult;
109
110 assert_ne!(
111 Config::default().highlighted_lines.0.check(17),
112 RangeCheckResult::InRange
113 );
114}