Add example config file.

This commit is contained in:
a-kenji 2021-03-12 22:05:41 +01:00
parent acc2524105
commit a86d8c2161
10 changed files with 85 additions and 63 deletions

View file

@ -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,]

View file

@ -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;

View file

@ -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,
}

View file

@ -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
}

View file

@ -1,5 +1,6 @@
//! The way terminal input is handled.
pub mod actions;
pub mod config;
pub mod handler;
pub mod keybinds;

View file

@ -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();
//}

View file

@ -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'), ],
//};
//}

View file

@ -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;

View file

@ -1,8 +0,0 @@
---
keybindings:
Normal:
- ? - F: 6
- F: 7
- F: 8
: - {GoToTab: 5}