diff options
| author | a-kenji <aks.kenji@protonmail.com> | 2021-05-11 22:09:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-11 22:09:33 +0200 |
| commit | 38b8f64ae641ae8f2ad993c2866d42b1f6a3d995 (patch) | |
| tree | 5d46cd3d0b5ceaaf7c79b1dfc6ccee15065923e6 /src | |
| parent | Merge pull request #488 from a-kenji/darwin-config-dir (diff) | |
| parent | !fixup Add Option for Simplified Layout (diff) | |
| download | sl0ppij-38b8f64ae641ae8f2ad993c2866d42b1f6a3d995.tar.gz sl0ppij-38b8f64ae641ae8f2ad993c2866d42b1f6a3d995.tar.xz sl0ppij-38b8f64ae641ae8f2ad993c2866d42b1f6a3d995.zip | |
Merge pull request #479 from a-kenji/simple-font-ui
Add Option for Simplified Layout
Diffstat (limited to 'src')
| -rw-r--r-- | src/cli.rs | 18 | ||||
| -rw-r--r-- | src/client/mod.rs | 6 | ||||
| -rw-r--r-- | src/common/input/config.rs | 21 | ||||
| -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 | 21 | ||||
| -rw-r--r-- | src/common/screen.rs | 14 | ||||
| -rw-r--r-- | src/server/mod.rs | 25 |
9 files changed, 91 insertions, 25 deletions
@@ -1,4 +1,5 @@ use super::common::utils::consts::{ZELLIJ_CONFIG_DIR_ENV, ZELLIJ_CONFIG_FILE_ENV}; +use crate::common::input::options::Options; use serde::{Deserialize, Serialize}; use std::path::PathBuf; use structopt::StructOpt; @@ -10,6 +11,10 @@ pub struct CliArgs { #[structopt(long)] pub max_panes: Option<usize>, + /// Speficy, if a simplified layout should be used that is compatible with more fonts + #[structopt(long)] + pub simplified: bool, + /// Change where zellij looks for layouts and plugins #[structopt(long)] pub data_dir: Option<PathBuf>, @@ -36,21 +41,20 @@ pub struct CliArgs { #[derive(Debug, StructOpt, Clone, Serialize, Deserialize)] pub enum ConfigCli { /// Change the behaviour of zellij - #[structopt(name = "option")] - Config { - /// Disables loading of configuration file at default location - #[structopt(long)] - clean: bool, - }, + #[structopt(name = "options")] + Options(Options), #[structopt(name = "generate-completion")] GenerateCompletion { shell: String }, #[structopt(name = "setup")] Setup { - /// Disables loading of configuration file at default location /// Dump the default configuration file to stdout #[structopt(long)] dump_config: bool, + /// Disables loading of configuration file at default location, + /// loads the defaults that zellij ships with + #[structopt(long)] + clean: bool, }, } diff --git a/src/client/mod.rs b/src/client/mod.rs index ba27bc3e..8fcbc070 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -42,7 +42,11 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs, config: C let full_screen_ws = os_input.get_terminal_size_using_fd(0); os_input.connect_to_server(); - os_input.send_to_server(ServerInstruction::NewClient(full_screen_ws, opts)); + os_input.send_to_server(ServerInstruction::NewClient( + full_screen_ws, + opts, + config.options.clone(), + )); os_input.set_raw_mode(0); let (send_client_instructions, receive_client_instructions): SyncChannelWithContext< diff --git a/src/common/input/config.rs b/src/common/input/config.rs index 3263b571..5f2656f3 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. @@ -172,7 +178,10 @@ mod config_test { #[test] fn try_from_cli_args_with_option_clean() { let mut opts = CliArgs::default(); - opts.option = Some(ConfigCli::Config { clean: true }); + opts.option = Some(ConfigCli::Setup { + clean: true, + dump_config: false, + }); let result = Config::try_from(&opts); assert!(result.is_ok()); } diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index aa204850..68a75448 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`]. @@ -149,6 +149,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 => { @@ -182,6 +183,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..3ff2fd8e --- /dev/null +++ b/src/common/input/options.rs @@ -0,0 +1,21 @@ +use serde::{Deserialize, Serialize}; +use structopt::StructOpt; + +#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)] +/// 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 + #[structopt(long)] + 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() + } + } +} diff --git a/src/common/screen.rs b/src/common/screen.rs index 44cfe3ba..6f5a4cb3 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -4,6 +4,8 @@ use std::collections::BTreeMap; use std::os::unix::io::RawFd; use std::str; +use crate::cli::ConfigCli; +use crate::common::input::options::Options; use crate::common::pty::{PtyInstruction, VteBytes}; use crate::common::thread_bus::Bus; use crate::errors::{ContextType, ScreenContext}; @@ -14,7 +16,7 @@ use crate::server::ServerInstruction; use crate::tab::Tab; use crate::wasm_vm::PluginInstruction; -use zellij_tile::data::{Event, InputMode, ModeInfo, Palette, TabInfo}; +use zellij_tile::data::{Event, InputMode, ModeInfo, Palette, PluginCapabilities, TabInfo}; /// Instructions that can be sent to the [`Screen`]. #[derive(Debug, Clone)] @@ -328,14 +330,24 @@ pub fn screen_thread_main( bus: Bus<ScreenInstruction>, max_panes: Option<usize>, full_screen_ws: PositionAndSize, + options: Option<ConfigCli>, + config_options: Options, ) { let colors = bus.os_input.as_ref().unwrap().load_palette(); + let capabilities = if let Some(ConfigCli::Options(options)) = options { + options.simplified_ui + } else { + config_options.simplified_ui + }; let mut screen = Screen::new( bus, &full_screen_ws, max_panes, ModeInfo { palette: colors, + capabilities: PluginCapabilities { + arrow_fonts: capabilities, + }, ..ModeInfo::default() }, InputMode::Normal, diff --git a/src/server/mod.rs b/src/server/mod.rs index 3655ed19..d9875727 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -12,7 +12,7 @@ use crate::client::ClientInstruction; use crate::common::thread_bus::{Bus, ThreadSenders}; use crate::common::{ errors::{ContextType, ServerContext}, - input::actions::Action, + input::{actions::Action, options::Options}, os_input_output::{set_permissions, ServerOsApi}, pty::{pty_thread_main, Pty, PtyInstruction}, screen::{screen_thread_main, ScreenInstruction}, @@ -30,7 +30,7 @@ use route::route_thread_main; #[derive(Serialize, Deserialize, Debug, Clone)] pub enum ServerInstruction { TerminalResize(PositionAndSize), - NewClient(PositionAndSize, CliArgs), + NewClient(PositionAndSize, CliArgs, Options), Action(Action), Render(Option<String>), UnblockInputThread, @@ -115,9 +115,14 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>) -> thread::JoinHandle<()> { let (instruction, mut err_ctx) = server_receiver.recv().unwrap(); err_ctx.add_call(ContextType::IPCServer(ServerContext::from(&instruction))); match instruction { - ServerInstruction::NewClient(full_screen_ws, opts) => { - let session_data = - init_session(os_input.clone(), opts, to_server.clone(), full_screen_ws); + ServerInstruction::NewClient(full_screen_ws, opts, config_options) => { + let session_data = init_session( + os_input.clone(), + opts, + config_options, + to_server.clone(), + full_screen_ws, + ); *sessions.write().unwrap() = Some(session_data); sessions .read() @@ -150,6 +155,7 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>) -> thread::JoinHandle<()> { fn init_session( os_input: Box<dyn ServerOsApi>, opts: CliArgs, + config_options: Options, to_server: SenderWithContext<ServerInstruction>, full_screen_ws: PositionAndSize, ) -> SessionMetaData { @@ -208,9 +214,16 @@ fn init_session( Some(os_input.clone()), ); let max_panes = opts.max_panes; + let options = opts.option; move || { - screen_thread_main(screen_bus, max_panes, full_screen_ws); + screen_thread_main( + screen_bus, + max_panes, + full_screen_ws, + options, + config_options, + ); } }) .unwrap(); |
