1use std::{collections::HashMap, path::PathBuf};
2
3use serde::{Deserialize, Serialize};
4
5use crate::action::Action;
6
7#[derive(Debug, Serialize, Deserialize, Clone)]
8#[serde(untagged)]
9pub enum KeyAction {
11 None,
13 Single(Action),
15 Multiple(Vec<Action>),
17 Nested(HashMap<String, KeyAction>),
19 Repeating(u16, Box<KeyAction>),
21}
22
23#[derive(Debug, Serialize, Deserialize, Default)]
24pub struct Keys {
26 #[serde(default)]
27 pub normal: HashMap<String, KeyAction>,
28 #[serde(default)]
29 pub insert: HashMap<String, KeyAction>,
30 #[serde(default)]
31 pub command: HashMap<String, KeyAction>,
32}
33
34#[derive(Debug, Serialize, Deserialize, Default)]
35pub struct Config {
37 pub keys: Keys,
39 pub theme: String,
41 pub log_file: Option<String>,
43 pub mouse_scroll_lines: Option<usize>,
45 #[serde(default = "default_false")]
46 pub window_borders_ascii: bool,
47}
48
49impl Config {
50 #[must_use]
51 pub fn path(p: &str) -> PathBuf {
59 std::env::home_dir()
60 .unwrap()
61 .join(".config")
62 .join("tsu")
63 .join(p)
64 }
65}
66
67#[must_use]
68pub fn default_false() -> bool {
73 false
74}
75
76#[cfg(test)]
77mod test {
78 use super::*;
79 use std::fs;
80
81 #[test]
82 fn test_parse_config() {
83 let toml = fs::read_to_string("default_config.toml").unwrap();
84 let config: Config = toml::from_str(&toml).unwrap();
85 println!("{config:#?}");
86 }
87}