1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use crate::line_range::{HighlightedLineRanges, LineRanges};
#[cfg(feature = "paging")]
use crate::paging::PagingMode;
use crate::style::StyleComponents;
use crate::syntax_mapping::SyntaxMapping;
use crate::wrapping::WrappingMode;
#[derive(Debug, Clone)]
pub enum VisibleLines {
Ranges(LineRanges),
#[cfg(feature = "git")]
DiffContext(usize),
}
impl VisibleLines {
pub fn diff_mode(&self) -> bool {
match self {
Self::Ranges(_) => false,
#[cfg(feature = "git")]
Self::DiffContext(_) => true,
}
}
}
impl Default for VisibleLines {
fn default() -> Self {
VisibleLines::Ranges(LineRanges::default())
}
}
#[derive(Debug, Clone, Default)]
pub struct Config<'a> {
pub language: Option<&'a str>,
pub show_nonprintable: bool,
pub term_width: usize,
pub tab_width: usize,
pub loop_through: bool,
pub colored_output: bool,
pub true_color: bool,
pub style_components: StyleComponents,
pub wrapping_mode: WrappingMode,
#[cfg(feature = "paging")]
pub paging_mode: PagingMode,
pub visible_lines: VisibleLines,
pub theme: String,
pub syntax_mapping: SyntaxMapping<'a>,
pub pager: Option<&'a str>,
pub use_italic_text: bool,
pub highlighted_lines: HighlightedLineRanges,
pub use_custom_assets: bool,
}
#[cfg(feature = "paging")]
pub fn get_pager_executable(config_pager: Option<&str>) -> Option<String> {
crate::pager::get_pager(config_pager)
.ok()
.flatten()
.map(|pager| pager.bin)
}
#[test]
fn default_config_should_include_all_lines() {
use crate::line_range::RangeCheckResult;
assert_eq!(LineRanges::default().check(17), RangeCheckResult::InRange);
}
#[test]
fn default_config_should_highlight_no_lines() {
use crate::line_range::RangeCheckResult;
assert_ne!(
Config::default().highlighted_lines.0.check(17),
RangeCheckResult::InRange
);
}