1use crossterm::event::KeyCode;
2use serde::{Deserialize, Serialize};
3use tui::style::Color;
4
5#[derive(Serialize, Deserialize, Default, Debug)]
7pub struct Configs {
8 pub colors: Colors,
9 pub keybindings: KeyBindings,
10}
11
12#[derive(Serialize, Deserialize, Debug)]
13pub struct Colors {
14 pub foreground: Color,
15 pub background: Color,
16 pub selection_fg: Color,
17 pub selection_bg: Color,
18 pub check_sign: Color,
19}
20
21impl Default for Colors {
22 fn default() -> Self {
23 Self {
24 foreground: Color::White,
25 background: Color::Black,
26 selection_fg: Color::Black,
27 selection_bg: Color::Yellow,
28 check_sign: Color::Green,
29 }
30 }
31}
32
33#[derive(Serialize, Deserialize, Debug)]
34pub struct KeyBindings {
35 pub exit_app: KeyCode,
36 pub new_quest: KeyCode,
37 pub check_and_uncheck_quest: KeyCode,
38 pub list_up: KeyCode,
39 pub list_down: KeyCode,
40 pub delete_quest: KeyCode,
41 pub exit_adding: KeyCode,
42 pub save_quest: KeyCode,
43}
44
45impl Default for KeyBindings {
46 fn default() -> Self {
47 Self {
48 exit_app: KeyCode::Char('q'),
49 new_quest: KeyCode::Char('n'),
50 check_and_uncheck_quest: KeyCode::Enter,
51 list_up: KeyCode::Up,
52 list_down: KeyCode::Down,
53 delete_quest: KeyCode::Delete,
54 exit_adding: KeyCode::Esc,
55 save_quest: KeyCode::Enter,
56 }
57 }
58}
59
60pub fn keycode_to_string(keycode: KeyCode) -> String {
62 let temp;
63
64 let stringified = match keycode {
65 KeyCode::Backspace => "Backspace",
66 KeyCode::Enter => "Enter",
67 KeyCode::Left => "←",
68 KeyCode::Right => "→",
69 KeyCode::Up => "↑",
70 KeyCode::Down => "↓",
71 KeyCode::Home => "Home",
72 KeyCode::End => "End",
73 KeyCode::PageUp => "Page Up",
74 KeyCode::PageDown => "Page Down",
75 KeyCode::Tab => "Tab",
76 KeyCode::BackTab => "Back Tab",
77 KeyCode::Delete => "Delete",
78 KeyCode::Insert => "Insert",
79 KeyCode::F(n) => {
80 temp = format!("F{}", n);
81 temp.as_str()
82 }
83 KeyCode::Char(char) => {
84 temp = char.to_string();
85 temp.as_str()
86 }
87 KeyCode::Null => "Null",
88 KeyCode::Esc => "Esc",
89 }
90 .to_string();
91
92 stringified
93}