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
|
pub(crate) mod theme;
mod utils;
use crate::config::theme::Theme;
use crate::config::utils::{editor_from_env, get_bool, get_color, get_input, get_string, open_git_config};
use crate::display::color::Color;
use std::convert::TryFrom;
#[derive(Clone, Debug)]
pub(crate) struct Config {
pub(crate) theme: Theme,
pub(crate) auto_select_next: bool,
pub(crate) comment_char: String,
pub(crate) editor: String,
pub(crate) input_abort: String,
pub(crate) input_action_break: String,
pub(crate) input_action_drop: String,
pub(crate) input_action_edit: String,
pub(crate) input_action_fixup: String,
pub(crate) input_action_pick: String,
pub(crate) input_action_reword: String,
pub(crate) input_action_squash: String,
pub(crate) input_confirm_no: String,
pub(crate) input_confirm_yes: String,
pub(crate) input_edit: String,
pub(crate) input_force_abort: String,
pub(crate) input_force_rebase: String,
pub(crate) input_help: String,
pub(crate) input_move_down: String,
pub(crate) input_move_down_step: String,
pub(crate) input_move_left: String,
pub(crate) input_move_right: String,
pub(crate) input_move_selection_down: String,
pub(crate) input_move_selection_up: String,
pub(crate) input_move_up: String,
pub(crate) input_move_up_step: String,
pub(crate) input_open_in_external_editor: String,
pub(crate) input_rebase: String,
pub(crate) input_show_commit: String,
pub(crate) input_toggle_visual_mode: String,
}
impl Config {
pub(crate) fn new() -> Result<Self, String> {
let git_config = open_git_config()?;
Ok(Config {
theme: Theme {
color_foreground: get_color(&git_config, "interactive-rebase-tool.foregroundColor", Color::White)?,
color_background: get_color(&git_config, "interactive-rebase-tool.backgroundColor", Color::Default)?,
color_selected_background: get_color(
&git_config,
"interactive-rebase-tool.selectedBackgroundColor",
Color::try_from("35,35,40").unwrap(),
)?,
color_indicator: get_color(&git_config, "interactive-rebase-tool.indicatorColor", Color::Cyan)?,
color_action_break: get_color(&git_config, "interactive-rebase-tool.breakColor", Color::White)?,
color_action_drop: get_color(&git_config, "interactive-rebase-tool.dropColor", Color::Red)?,
color_action_edit: get_color(&git_config, "interactive-rebase-tool.editColor", Color::Blue)?,
color_action_exec: get_color(&git_config, "interactive-rebase-tool.execColor", Color::White)?,
color_action_fixup: get_color(&git_config, "interactive-rebase-tool.fixupColor", Color::Magenta)?,
color_action_pick: get_color(&git_config, "interactive-rebase-tool.pickColor", Color::Green)?,
color_action_reword: get_color(&git_config, "interactive-rebase-tool.rewordColor", Color::Yellow)?,
color_action_squash: get_color(&git_config, "interactive-rebase-tool.squashColor", Color::Cyan)?,
color_diff_add: get_color(&git_config, "interactive-rebase-tool.diffAddColor", Color::Green)?,
color_diff_change: get_color(&git_config, "interactive-rebase-tool.diffChangeColor", Color::Yellow)?,
color_diff_remove: get_color(&git_config, "interactive-rebase-tool.diffRemoveColor", Color::Red)?,
character_vertical_spacing: get_string(
&git_config,
"interactive-rebase-tool.verticalSpacingCharacter",
"~",
)?,
},
auto_select_next: get_bool(&git_config, "interactive-rebase-tool.autoSelectNext", false)?,
comment_char: get_string(&git_config, "core.commentChar", "#")?,
editor: get_string(&git_config, "core.editor", editor_from_env().as_str())?,
input_abort: get_input(&git_config, "interactive-rebase-tool.inputAbort", "q")?,
input_action_break: get_input(&git_config, "interactive-rebase-tool.inputActionBreak", "b")?,
input_action_drop: get_input(&git_config, "interactive-rebase-tool.inputActionDrop", "d")?,
input_action_edit: get_input(&git_config, "interactive-rebase-tool.inputActionEdit", "e")?,
input_action_fixup: get_input(&git_config, "interactive-rebase-tool.inputActionFixup", "f")?,
input_action_pick: get_input(&git_config, "interactive-rebase-tool.inputActionPick", "p")?,
input_action_reword: get_input(&git_config, "interactive-rebase-tool.inputActionReword", "r")?,
input_action_squash: get_input(&git_config, "interactive-rebase-tool.inputActionSquash", "s")?,
input_confirm_no: get_input(&git_config, "interactive-rebase-tool.inputConfirmNo", "n")?,
input_confirm_yes: get_input(&git_config, "interactive-rebase-tool.inputConfirmYes", "y")?,
input_edit: get_input(&git_config, "interactive-rebase-tool.inputEdit", "E")?,
input_force_abort: get_input(&git_config, "interactive-rebase-tool.inputForceAbort", "Q")?,
input_force_rebase: get_input(&git_config, "interactive-rebase-tool.inputForceRebase", "W")?,
input_help: get_input(&git_config, "interactive-rebase-tool.inputHelp", "?")?,
input_move_down: get_input(&git_config, "interactive-rebase-tool.inputMoveDown", "Down")?,
input_move_left: get_input(&git_config, "interactive-rebase-tool.inputMoveLeft", "Left")?,
input_move_right: get_input(&git_config, "interactive-rebase-tool.inputMoveRight", "Right")?,
input_move_up_step: get_input(&git_config, "interactive-rebase-tool.inputMoveStepUp", "PageUp")?,
input_move_down_step: get_input(&git_config, "interactive-rebase-tool.inputMoveStepDown", "PageDown")?,
input_move_selection_down: get_input(&git_config, "interactive-rebase-tool.inputMoveSelectionDown", "j")?,
input_move_selection_up: get_input(&git_config, "interactive-rebase-tool.inputMoveSelectionUp", "k")?,
input_move_up: get_input(&git_config, "interactive-rebase-tool.inputMoveUp", "Up")?,
input_open_in_external_editor: get_input(
&git_config,
"interactive-rebase-tool.inputOpenInExternalEditor",
"!",
)?,
input_rebase: get_input(&git_config, "interactive-rebase-tool.inputRebase", "w")?,
input_show_commit: get_input(&git_config, "interactive-rebase-tool.inputShowCommit", "c")?,
input_toggle_visual_mode: get_input(&git_config, "interactive-rebase-tool.inputToggleVisualMode", "v")?,
})
}
}
|