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
115
116
117
118
119
120
121
122
123
use {
super::*,
crate::{
cli::AppLaunchArgs,
conf::Conf,
errors::ConfError,
icon::*,
pattern::SearchModeMap,
skin::ExtColorMap,
tree::SpecialPath,
verb::VerbStore,
},
std::{
convert::{TryFrom, TryInto},
path::PathBuf,
},
};
pub struct AppContext {
pub config_paths: Vec<PathBuf>,
pub launch_args: AppLaunchArgs,
pub verb_store: VerbStore,
pub special_paths: Vec<SpecialPath>,
pub search_modes: SearchModeMap,
pub show_selection_mark: bool,
pub ext_colors: ExtColorMap,
pub syntax_theme: Option<String>,
pub standard_status: StandardStatus,
pub true_colors: bool,
pub icons: Option<Box<dyn IconPlugin + Send + Sync>>,
}
impl AppContext {
pub fn from(
launch_args: AppLaunchArgs,
verb_store: VerbStore,
config: &Conf,
) -> Result<Self, ConfError> {
let config_paths = config.files.clone();
let standard_status = StandardStatus::new(&verb_store);
let true_colors = if let Some(value) = config.true_colors {
value
} else {
are_true_colors_available()
};
let icons = config.icon_theme.as_ref()
.and_then(|itn| icon_plugin(itn));
let special_paths = config.special_paths
.iter()
.map(|(k, v)| SpecialPath::new(k.clone(), *v))
.collect();
let search_modes = config
.search_modes
.as_ref()
.map(|map| map.try_into())
.transpose()?
.unwrap_or_default();
let ext_colors = ExtColorMap::try_from(&config.ext_colors)?;
Ok(Self {
config_paths,
launch_args,
verb_store,
special_paths,
search_modes,
show_selection_mark: config.show_selection_mark.unwrap_or(false),
ext_colors,
syntax_theme: config.syntax_theme.clone(),
standard_status,
true_colors,
icons,
})
}
}
fn are_true_colors_available() -> bool {
if let Ok(colorterm) = std::env::var("COLORTERM") {
debug!("COLORTERM env variable = {:?}", colorterm);
if colorterm.contains("truecolor") || colorterm.contains("24bit") {
debug!("true colors are available");
true
} else {
false
}
} else {
true
}
}