summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-03-12 22:05:41 +0100
committera-kenji <aks.kenji@protonmail.com>2021-03-12 22:05:41 +0100
commita86d8c216186030754a42968768f2af6a131d90d (patch)
tree4e445340579663436ba6fb564a6b8403abd8fdb7
parentacc2524105f811d1b32e3b993d91c67968efe33e (diff)
Add example config file.
-rw-r--r--example/config.yaml (renamed from config.yaml)8
-rw-r--r--src/common/input/config.rs (renamed from src/common/config.rs)7
-rw-r--r--src/common/input/handler.rs9
-rw-r--r--src/common/input/keybinds.rs6
-rw-r--r--src/common/input/mod.rs1
-rw-r--r--src/common/input/ut/config_test.rs31
-rw-r--r--src/common/input/ut/keybinds_test.rs75
-rw-r--r--src/common/mod.rs3
-rw-r--r--src/tests/fixtures/config/functioning_simple_config.yaml0
-rw-r--r--src/tests/fixtures/config/multiple_keys_for_one_action.yaml8
10 files changed, 85 insertions, 63 deletions
diff --git a/config.yaml b/example/config.yaml
index eb227d4ed..f19a21146 100644
--- a/config.yaml
+++ b/example/config.yaml
@@ -1,6 +1,6 @@
---
keybinds:
- Normal:
+ normal:
- action: [GoToTab: 1,]
key: [F: 1,]
- action: [GoToTab: 2,]
@@ -8,10 +8,6 @@ keybinds:
- action: [GoToTab: 3,]
key: [F: 3,]
- action: [GoToTab: 4,]
- key: [F: 3,]
+ key: [F: 4,]
- action: [NewTab,]
key: [F: 5,]
- - action: [NewPane: Right, NewPane: Right,]
- key: [F: 6,]
- - action: [NewPane: Right, NewPane: Right,]
- key: [F: 6,]
diff --git a/src/common/config.rs b/src/common/input/config.rs
index 4a66acb07..b63ccef1d 100644
--- a/src/common/config.rs
+++ b/src/common/input/config.rs
@@ -5,7 +5,7 @@ use std::fs::File;
use std::io::{self, Read};
use std::path::{Path, PathBuf};
-use super::input::keybinds::{Keybinds, KeybindsFromYaml};
+use super::keybinds::{Keybinds, KeybindsFromYaml};
use crate::utils::logging::*;
use directories_next::ProjectDirs;
@@ -61,9 +61,6 @@ impl Config {
Ok(Config::from_yaml(&yaml_config)?)
}
Err(e) => {
- // TODO logging, if a file is not found
- // at an expected position - should not
- // panic, but log to file @a-kenji
debug_log_to_file(format!(
"{}\nUsing the default configuration!",
ConfigError::IoPath(e, path.to_path_buf())
@@ -123,5 +120,5 @@ impl From<serde_yaml::Error> for ConfigError {
// The unit test location.
#[cfg(test)]
-#[path = "./input/ut/config_test.rs"]
+#[path = "./ut/config_test.rs"]
mod config_test;
diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs
index 862cc0d29..dc9fa3823 100644
--- a/src/common/input/handler.rs
+++ b/src/common/input/handler.rs
@@ -2,7 +2,7 @@
use super::actions::Action;
use super::keybinds::Keybinds;
-use crate::common::config::Config;
+use crate::common::input::config::Config;
use crate::common::{update_state, AppInstruction, AppState, SenderWithContext, OPENCALLS};
use crate::errors::ContextType;
use crate::os_input_output::OsApi;
@@ -273,18 +273,25 @@ impl InputHandler {
pub enum InputMode {
/// In `Normal` mode, input is always written to the terminal, except for the shortcuts leading
/// to other modes
+ #[serde(alias = "normal")]
Normal,
/// In `Locked` mode, input is always written to the terminal and all shortcuts are disabled
/// except the one leading back to normal mode
+ #[serde(alias = "locked")]
Locked,
/// `Resize` mode allows resizing the different existing panes.
+ #[serde(alias = "resize")]
Resize,
/// `Pane` mode allows creating and closing panes, as well as moving between them.
+ #[serde(alias = "pane")]
Pane,
/// `Tab` mode allows creating and closing tabs, as well as moving between them.
+ #[serde(alias = "tab")]
Tab,
/// `Scroll` mode allows scrolling up and down within a pane.
+ #[serde(alias = "scroll")]
Scroll,
+ #[serde(alias = "renametab")]
RenameTab,
}
diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs
index d7f646523..0c37693c1 100644
--- a/src/common/input/keybinds.rs
+++ b/src/common/input/keybinds.rs
@@ -56,7 +56,7 @@ impl Keybinds {
fn merge_keybinds(&self, other: Keybinds) -> Keybinds {
let mut keybinds = Keybinds::new();
- for mode in self.0.keys().chain(other.0.keys()) {
+ for mode in InputMode::iter() {
let mut mode_keybinds = ModeKeybinds::new();
if let Some(keybind) = self.0.get(&mode) {
mode_keybinds.0.extend(keybind.0.clone());
@@ -64,7 +64,9 @@ impl Keybinds {
if let Some(keybind) = other.0.get(&mode) {
mode_keybinds.0.extend(keybind.0.clone());
}
- keybinds.0.insert(mode.clone(), mode_keybinds);
+ if !mode_keybinds.0.is_empty() {
+ keybinds.0.insert(mode, mode_keybinds);
+ }
}
keybinds
}
diff --git a/src/common/input/mod.rs b/src/common/input/mod.rs
index a7dca7ed0..6589cac2c 100644
--- a/src/common/input/mod.rs
+++ b/src/common/input/mod.rs
@@ -1,5 +1,6 @@
//! The way terminal input is handled.
pub mod actions;
+pub mod config;
pub mod handler;
pub mod keybinds;
diff --git a/src/common/input/ut/config_test.rs b/src/common/input/ut/config_test.rs
index 17649d14d..eb4bc960f 100644
--- a/src/common/input/ut/config_test.rs
+++ b/src/common/input/ut/config_test.rs
@@ -1,12 +1,8 @@
//! For Configuration Options
use super::super::config::*;
-use crate::common::input::actions::*;
-use crate::common::input::keybinds::*;
use std::path::PathBuf;
-use termion::event::Key;
-
#[test]
fn no_config_file_equals_default_config() {
let no_file = PathBuf::from(r"../fixtures/config/config.yamlll");
@@ -21,30 +17,3 @@ fn no_config_option_file_equals_default_config() {
let default = Config::default();
assert_eq!(config, default);
}
-
-//#[test]
-//fn multiple_keys_mapped_to_one_action() {
-//let options = r"
-//---
-//keybindings:
-//Normal:
-//- ? - F: 6
-//- F: 7
-//- F: 8
-//: - {GoToTab: 5}
-//";
-
-//let config_options = Config::from_yaml(&options).unwrap();
-
-//assert_eq!(config_options, config_options)
-//}
-
-//#[test]
-//fn merge_keybinds_merges(){
-//let mut self_keybinds = Keybinds::new();
-//let mut self_mode_keybinds = ModeKeybinds::new();
-//self_mode_keybinds.0.insert(Key::F(1), vec![Action::GoToTab(5)]);
-//let mut other_keybinds = Keybinds::new();
-//let mut self_mode_keybinds = ModeKeybinds::new();
-//let mut expected = Keybinds::new();
-//}
diff --git a/src/common/input/ut/keybinds_test.rs b/src/common/input/ut/keybinds_test.rs
index 444729858..2b306bc32 100644
--- a/src/common/input/ut/keybinds_test.rs
+++ b/src/common/input/ut/keybinds_test.rs
@@ -60,17 +60,76 @@ fn merge_keybinds_merges() {
.0
.insert(InputMode::Resize, mode_keybinds_other.clone());
let mut keybinds_expected = Keybinds::new();
- keybinds_expected.0.insert(
- InputMode::Normal,
- mode_keybinds_self
- );
- keybinds_expected.0.insert(
- InputMode::Resize,
- mode_keybinds_other
- );
+ keybinds_expected
+ .0
+ .insert(InputMode::Normal, mode_keybinds_self);
+ keybinds_expected
+ .0
+ .insert(InputMode::Resize, mode_keybinds_other);
assert_eq!(
keybinds_expected,
keybinds_self.merge_keybinds(keybinds_other)
)
}
+
+#[test]
+fn merge_keybinds_overwrites_same_keys() {
+ let mut mode_keybinds_self = ModeKeybinds::new();
+ mode_keybinds_self.0.insert(Key::F(1), vec![Action::NoOp]);
+ mode_keybinds_self.0.insert(Key::F(2), vec![Action::NoOp]);
+ mode_keybinds_self.0.insert(Key::F(3), vec![Action::NoOp]);
+ let mut mode_keybinds_other = ModeKeybinds::new();
+ mode_keybinds_other
+ .0
+ .insert(Key::F(1), vec![Action::GoToTab(1)]);
+ mode_keybinds_other
+ .0
+ .insert(Key::F(2), vec![Action::GoToTab(2)]);
+ mode_keybinds_other
+ .0
+ .insert(Key::F(3), vec![Action::GoToTab(3)]);
+ let mut keybinds_self = Keybinds::new();
+ keybinds_self
+ .0
+ .insert(InputMode::Normal, mode_keybinds_self.clone());
+ let mut keybinds_other = Keybinds::new();
+ keybinds_other
+ .0
+ .insert(InputMode::Normal, mode_keybinds_other.clone());
+ let mut keybinds_expected = Keybinds::new();
+ keybinds_expected
+ .0
+ .insert(InputMode::Normal, mode_keybinds_other);
+
+ assert_eq!(
+ keybinds_expected,
+ keybinds_self.merge_keybinds(keybinds_other)
+ )
+}
+
+#[test]
+fn from_keyaction_from_yaml_to_mode_keybindings() {
+ let actions = vec![Action::NoOp, Action::GoToTab(1)];
+ let keyaction = KeyActionFromYaml {
+ action: actions.clone(),
+ key: vec![Key::F(1), Key::Backspace, Key::Char('t')],
+ };
+
+ let mut expected = ModeKeybinds::new();
+ expected.0.insert(Key::F(1), actions.clone());
+ expected.0.insert(Key::Backspace, actions.clone());
+ expected.0.insert(Key::Char('t'), actions);
+
+ assert_eq!(expected, ModeKeybinds::from(keyaction));
+}
+
+//#[test]
+//fn from_keybinds_from_yaml_to_keybinds(){
+//let mut keybinds_from_yaml = KeybindsFromYaml(HashMap<InputMode, Vec<KeyActionFromYaml>>);
+//let actions = vec![Action::NoOp, Action::GoToTab(1), ];
+//let keyaction = KeyActionFromYaml {
+//action : actions.clone(),
+//key : vec![ Key::F(1), Key::Backspace , Key::Char('t'), ],
+//};
+//}
diff --git a/src/common/mod.rs b/src/common/mod.rs
index c9b4959ae..8351bc4a5 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -1,5 +1,4 @@
pub mod command_is_executing;
-pub mod config;
pub mod errors;
pub mod input;
pub mod install;
@@ -27,7 +26,7 @@ use wasmer::{ChainableNamedResolver, Instance, Module, Store, Value};
use wasmer_wasi::{Pipe, WasiState};
use crate::cli::CliArgs;
-use crate::common::config::Config;
+use crate::common::input::config::Config;
use crate::layout::Layout;
use crate::utils::logging::*;
use command_is_executing::CommandIsExecuting;
diff --git a/src/tests/fixtures/config/functioning_simple_config.yaml b/src/tests/fixtures/config/functioning_simple_config.yaml
deleted file mode 100644
index e69de29bb..000000000
--- a/src/tests/fixtures/config/functioning_simple_config.yaml
+++ /dev/null
diff --git a/src/tests/fixtures/config/multiple_keys_for_one_action.yaml b/src/tests/fixtures/config/multiple_keys_for_one_action.yaml
deleted file mode 100644
index 7da625417..000000000
--- a/src/tests/fixtures/config/multiple_keys_for_one_action.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
----
-keybindings:
- Normal:
- - ? - F: 6
- - F: 7
- - F: 8
- : - {GoToTab: 5}
-