diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-05-09 16:44:05 +0200 |
|---|---|---|
| committer | a-kenji <aks.kenji@protonmail.com> | 2021-05-10 16:03:06 +0200 |
| commit | 088bcf3dd8aab4e522cface84c0a260b5b37a87c (patch) | |
| tree | 5ed94988521c3caa2eefc00277569345e0f0d8f6 /src/common/input | |
| parent | README: shortening + add explanation (#470) (diff) | |
| download | sl0ppij-088bcf3dd8aab4e522cface84c0a260b5b37a87c.tar.gz sl0ppij-088bcf3dd8aab4e522cface84c0a260b5b37a87c.tar.xz sl0ppij-088bcf3dd8aab4e522cface84c0a260b5b37a87c.zip | |
Add Option for Simplified Layout
* the simplified layout omits the Nerdfonts characters that are not
found in every Fontset
* add an optional config option to opt into the simplified ui
`simplified_ui: bool`
* add a config flag that allows opting into the simplified ui
`zellij options --simplified-ui`
* move the `clean` flag to the `setup` subcommand
Diffstat (limited to 'src/common/input')
| -rw-r--r-- | src/common/input/config.rs | 16 | ||||
| -rw-r--r-- | src/common/input/handler.rs | 4 | ||||
| -rw-r--r-- | src/common/input/keybinds.rs | 6 | ||||
| -rw-r--r-- | src/common/input/mod.rs | 1 | ||||
| -rw-r--r-- | src/common/input/options.rs | 19 |
5 files changed, 37 insertions, 9 deletions
diff --git a/src/common/input/config.rs b/src/common/input/config.rs index 3263b571..019d1c4c 100644 --- a/src/common/input/config.rs +++ b/src/common/input/config.rs @@ -6,10 +6,11 @@ use std::io::{self, Read}; use std::path::{Path, PathBuf}; use super::keybinds::{Keybinds, KeybindsFromYaml}; +use super::options::Options; use crate::cli::{CliArgs, ConfigCli}; use crate::common::setup; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std::convert::TryFrom; const DEFAULT_CONFIG_FILE_NAME: &str = "config.yaml"; @@ -19,13 +20,16 @@ type ConfigResult = Result<Config, ConfigError>; /// Intermediate deserialization config struct #[derive(Debug, Deserialize)] pub struct ConfigFromYaml { + #[serde(flatten)] + pub options: Option<Options>, pub keybinds: Option<KeybindsFromYaml>, } /// Main configuration. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct Config { pub keybinds: Keybinds, + pub options: Options, } #[derive(Debug)] @@ -43,7 +47,8 @@ pub enum ConfigError { impl Default for Config { fn default() -> Self { let keybinds = Keybinds::default(); - Config { keybinds } + let options = Options::default(); + Config { keybinds, options } } } @@ -55,7 +60,7 @@ impl TryFrom<&CliArgs> for Config { return Config::new(&path); } - if let Some(ConfigCli::Config { clean, .. }) = opts.option { + if let Some(ConfigCli::Setup { clean, .. }) = opts.option { if clean { return Config::from_default_assets(); } @@ -84,7 +89,8 @@ impl Config { pub fn from_yaml(yaml_config: &str) -> ConfigResult { let config_from_yaml: ConfigFromYaml = serde_yaml::from_str(&yaml_config)?; let keybinds = Keybinds::get_default_keybinds_with_config(config_from_yaml.keybinds); - Ok(Config { keybinds }) + let options = Options::from_yaml(config_from_yaml.options); + Ok(Config { keybinds, options }) } /// Deserializes from given path. diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index a4293220..6238a3ee 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -11,7 +11,7 @@ use crate::server::ServerInstruction; use crate::CommandIsExecuting; use termion::input::{TermRead, TermReadEventsAndRaw}; -use zellij_tile::data::{InputMode, Key, ModeInfo, Palette}; +use zellij_tile::data::{InputMode, Key, ModeInfo, Palette, PluginCapabilities}; /// Handles the dispatching of [`Action`]s according to the current /// [`InputMode`], and keep tracks of the current [`InputMode`]. @@ -148,6 +148,7 @@ impl InputHandler { // TODO this should probably be automatically generated in some way pub fn get_mode_info(mode: InputMode, palette: Palette) -> ModeInfo { let mut keybinds: Vec<(String, String)> = vec![]; + let capabilities = PluginCapabilities { arrow_fonts: true }; match mode { InputMode::Normal | InputMode::Locked => {} InputMode::Resize => { @@ -181,6 +182,7 @@ pub fn get_mode_info(mode: InputMode, palette: Palette) -> ModeInfo { mode, keybinds, palette, + capabilities, } } diff --git a/src/common/input/keybinds.rs b/src/common/input/keybinds.rs index 823ca264..8bef47fd 100644 --- a/src/common/input/keybinds.rs +++ b/src/common/input/keybinds.rs @@ -4,14 +4,14 @@ use std::collections::HashMap; use super::actions::Action; use super::config; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use strum::IntoEnumIterator; use zellij_tile::data::*; /// Used in the config struct -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct Keybinds(HashMap<InputMode, ModeKeybinds>); -#[derive(Clone, Debug, Default, PartialEq)] +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct ModeKeybinds(HashMap<Key, Vec<Action>>); /// Intermediate struct used for deserialisation diff --git a/src/common/input/mod.rs b/src/common/input/mod.rs index 6589cac2..f30ccf23 100644 --- a/src/common/input/mod.rs +++ b/src/common/input/mod.rs @@ -4,3 +4,4 @@ pub mod actions; pub mod config; pub mod handler; pub mod keybinds; +pub mod options; diff --git a/src/common/input/options.rs b/src/common/input/options.rs new file mode 100644 index 00000000..4c2dd861 --- /dev/null +++ b/src/common/input/options.rs @@ -0,0 +1,19 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize)] +/// Options that can be set either through the config file, +/// or cli flags +pub struct Options { + /// Allow plugins to use a more compatible font type + pub simplified_ui: bool, +} + +impl Options { + pub fn from_yaml(from_yaml: Option<Options>) -> Options { + if let Some(opts) = from_yaml { + opts + } else { + Options::default() + } + } +} |
