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
|
use std::convert::From;
use serde_derive::Deserialize;
use tui::layout::Constraint;
use crate::config::option::DisplayOption;
use super::sort_crude::SortOptionCrude;
pub const fn default_column_ratio() -> (usize, usize, usize) {
(1, 3, 4)
}
const fn default_true() -> bool {
true
}
const fn default_scroll_offset() -> usize {
4
}
#[derive(Clone, Debug, Deserialize)]
pub struct DisplayOptionCrude {
#[serde(default)]
pub automatically_count_files: bool,
#[serde(default = "default_true")]
pub collapse_preview: bool,
#[serde(default)]
pub column_ratio: Option<[usize; 3]>,
#[serde(default = "default_scroll_offset")]
pub scroll_offset: usize,
#[serde(default = "default_true")]
pub show_borders: bool,
#[serde(default)]
pub show_hidden: bool,
#[serde(default)]
pub show_icons: bool,
#[serde(default = "default_true")]
pub show_preview: bool,
#[serde(default = "default_true")]
pub tilde_in_titlebar: bool,
#[serde(default, rename = "sort")]
pub sort_options: SortOptionCrude,
}
impl std::default::Default for DisplayOptionCrude {
fn default() -> Self {
Self {
automatically_count_files: false,
collapse_preview: true,
column_ratio: None,
scroll_offset: 4,
show_borders: true,
show_hidden: false,
show_icons: false,
show_preview: true,
sort_options: SortOptionCrude::default(),
tilde_in_titlebar: true,
}
}
}
impl From<DisplayOptionCrude> for DisplayOption {
fn from(crude: DisplayOptionCrude) -> Self {
let column_ratio = match crude.column_ratio {
Some(s) => (s[0], s[1], s[2]),
_ => default_column_ratio(),
};
let total = (column_ratio.0 + column_ratio.1 + column_ratio.2) as u32;
let default_layout = [
Constraint::Ratio(column_ratio.0 as u32, total),
Constraint::Ratio(column_ratio.1 as u32, total),
Constraint::Ratio(column_ratio.2 as u32, total),
];
let no_preview_layout = [
Constraint::Ratio(column_ratio.0 as u32, total),
Constraint::Ratio(column_ratio.1 as u32 + column_ratio.2 as u32, total),
Constraint::Ratio(0, total),
];
Self {
_automatically_count_files: crude.automatically_count_files,
_collapse_preview: crude.collapse_preview,
_scroll_offset: crude.scroll_offset,
_show_borders: crude.show_borders,
_show_hidden: crude.show_hidden,
_show_icons: crude.show_icons,
_show_preview: crude.show_preview,
_sort_options: crude.sort_options.into(),
_tilde_in_titlebar: crude.tilde_in_titlebar,
column_ratio,
default_layout,
no_preview_layout,
}
}
}
|