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
|
use super::layout::Split;
use serde::{Deserialize, Serialize};
use std::fs::read_to_string;
use std::path::Path;
#[allow(dead_code)]
pub const SESSION_EXAMPLE: &str = "sort_by = \"Name\"
show_hidden = false
preview = false
split = Vertical
";
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Session {
pub sort_by: SortKey,
pub show_hidden: bool,
pub preview: Option<bool>,
pub split: Option<Split>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub enum SortKey {
Name,
Time,
}
pub fn read_session(session_path: &Path) -> Session {
match read_to_string(session_path) {
Ok(s) => match serde_yaml::from_str(&s) {
Ok(de) => de,
Err(_) => Session {
sort_by: SortKey::Name,
show_hidden: true,
preview: Some(false),
split: Some(Split::Vertical),
},
},
Err(_) => Session {
sort_by: SortKey::Name,
show_hidden: true,
preview: Some(false),
split: Some(Split::Vertical),
},
}
}
|