From 80fe803ffd49c0aa05c3883d04c0239e5dd5bae1 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Fri, 14 May 2021 23:28:30 +0200 Subject: [PATCH 1/9] Default mode 368 * Parsing Implemented * Adds option to specify a default mode either through a flag `--options default-mode [MODE]`, or a configuration option `default_mode: [MODE]` closes #368 --- src/client/mod.rs | 5 ++++- src/common/input/handler.rs | 5 ++++- src/common/input/options.rs | 14 +++++++++++++- src/common/screen.rs | 4 +++- zellij-tile/src/data.rs | 18 ++++++++++++++++++ 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index 6f298615..8d83b626 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -20,6 +20,7 @@ use crate::common::{ thread_bus::{SenderType, SenderWithContext, SyncChannelWithContext}, }; use crate::server::ServerInstruction; +use zellij_tile::data::InputMode; /// Instructions related to the client-side application and sent from server to client #[derive(Serialize, Deserialize, Debug, Clone)] @@ -54,7 +55,7 @@ pub fn start_client(mut os_input: Box, opts: CliArgs, config: C os_input.send_to_server(ServerInstruction::NewClient( full_screen_ws, opts, - config_options, + config_options.clone(), )); os_input.set_raw_mode(0); let _ = os_input @@ -83,12 +84,14 @@ pub fn start_client(mut os_input: Box, opts: CliArgs, config: C let send_client_instructions = send_client_instructions.clone(); let command_is_executing = command_is_executing.clone(); let os_input = os_input.clone(); + let default_mode = config_options.default_mode.unwrap_or(InputMode::Normal); move || { input_loop( os_input, config, command_is_executing, send_client_instructions, + default_mode, ) } }); diff --git a/src/common/input/handler.rs b/src/common/input/handler.rs index b2f4d0a3..7dabc71e 100644 --- a/src/common/input/handler.rs +++ b/src/common/input/handler.rs @@ -33,9 +33,10 @@ impl InputHandler { command_is_executing: CommandIsExecuting, config: Config, send_client_instructions: SenderWithContext, + mode: InputMode, ) -> Self { InputHandler { - mode: InputMode::Normal, + mode, os_input, config, command_is_executing, @@ -225,12 +226,14 @@ pub fn input_loop( config: Config, command_is_executing: CommandIsExecuting, send_client_instructions: SenderWithContext, + default_mode: InputMode, ) { let _handler = InputHandler::new( os_input, command_is_executing, config, send_client_instructions, + default_mode, ) .handle_input(); } diff --git a/src/common/input/options.rs b/src/common/input/options.rs index 33625b65..0c5909d0 100644 --- a/src/common/input/options.rs +++ b/src/common/input/options.rs @@ -2,6 +2,7 @@ use crate::cli::ConfigCli; use serde::{Deserialize, Serialize}; use structopt::StructOpt; +use zellij_tile::data::InputMode; #[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)] /// Options that can be set either through the config file, @@ -11,6 +12,9 @@ pub struct Options { /// that is compatible with more fonts #[structopt(long)] pub simplified_ui: bool, + /// Allows to specify the default mode + #[structopt(long)] + pub default_mode: Option, } impl Options { @@ -32,7 +36,15 @@ impl Options { self.simplified_ui }; - Options { simplified_ui } + let default_mode = match other.default_mode { + None => self.default_mode, + other => other, + }; + + Options { + simplified_ui, + default_mode, + } } pub fn from_cli(&self, other: Option) -> Options { diff --git a/src/common/screen.rs b/src/common/screen.rs index bc99f953..dbdccb86 100644 --- a/src/common/screen.rs +++ b/src/common/screen.rs @@ -333,6 +333,7 @@ pub fn screen_thread_main( ) { let colors = bus.os_input.as_ref().unwrap().load_palette(); let capabilities = config_options.simplified_ui; + let default_mode = config_options.default_mode.unwrap_or_default(); let mut screen = Screen::new( bus, @@ -343,9 +344,10 @@ pub fn screen_thread_main( capabilities: PluginCapabilities { arrow_fonts: capabilities, }, + mode: default_mode, ..ModeInfo::default() }, - InputMode::Normal, + default_mode, colors, ); loop { diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index c1b9c30e..cf9c8265 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use std::str::FromStr; use strum_macros::{EnumDiscriminants, EnumIter, EnumString, ToString}; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -89,6 +90,23 @@ impl Default for PaletteColor { } } +impl FromStr for InputMode { + type Err = Box; + + fn from_str(s: &str) -> Result { + match s { + "normal" => Ok(InputMode::Normal), + "resize" => Ok(InputMode::Resize), + "locked" => Ok(InputMode::Locked), + "pane" => Ok(InputMode::Pane), + "tab" => Ok(InputMode::Tab), + "scroll" => Ok(InputMode::Scroll), + "renametab" => Ok(InputMode::RenameTab), + e => Err(e.to_string().into()), + } + } +} + #[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] pub enum PaletteSource { Default, From ec5476d3a593e20f11a898338a941fb90e0cab1b Mon Sep 17 00:00:00 2001 From: a-kenji Date: Thu, 27 May 2021 16:00:16 +0200 Subject: [PATCH 2/9] fixup! rustfmt --- zellij-client/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index d854b6d3..8908b6bc 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -135,7 +135,11 @@ pub fn start_client( #[cfg(any(feature = "test", test))] let first_msg = { let _ = SESSION_NAME.set("".into()); - ClientToServerMsg::NewClient(client_attributes, Box::new(opts), Box::new(config_options.clone())) + ClientToServerMsg::NewClient( + client_attributes, + Box::new(opts), + Box::new(config_options.clone()), + ) }; os_input.connect_to_server(&*ZELLIJ_IPC_PIPE); From 09d12f8cbd27efa99db47dc412a09872565ecd86 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Sat, 29 May 2021 14:19:40 +0200 Subject: [PATCH 3/9] Fix build on platforms with TIOCGWINSZ / ioctl() integer type mismatch. --- zellij-client/src/os_input_output.rs | 8 +++++++- zellij-server/src/os_input_output.rs | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/zellij-client/src/os_input_output.rs b/zellij-client/src/os_input_output.rs index 0606ae37..405422ab 100644 --- a/zellij-client/src/os_input_output.rs +++ b/zellij-client/src/os_input_output.rs @@ -45,7 +45,13 @@ pub(crate) fn get_terminal_size_using_fd(fd: RawFd) -> PositionAndSize { ws_ypixel: 0, }; - unsafe { ioctl(fd, TIOCGWINSZ, &mut winsize) }; + // TIOCGWINSZ is an u32, but the second argument to ioctl is u64 on + // some platforms. When checked on Linux, clippy will complain about + // useless conversion. + #[allow(clippy::useless_conversion)] + unsafe { + ioctl(fd, TIOCGWINSZ.into(), &mut winsize) + }; PositionAndSize::from(winsize) } diff --git a/zellij-server/src/os_input_output.rs b/zellij-server/src/os_input_output.rs index 4cda73ed..91a228e7 100644 --- a/zellij-server/src/os_input_output.rs +++ b/zellij-server/src/os_input_output.rs @@ -41,7 +41,11 @@ pub(crate) fn set_terminal_size_using_fd(fd: RawFd, columns: u16, rows: u16) { ws_xpixel: 0, ws_ypixel: 0, }; - unsafe { ioctl(fd, TIOCSWINSZ, &winsize) }; + // TIOCGWINSZ is an u32, but the second argument to ioctl is u64 on + // some platforms. When checked on Linux, clippy will complain about + // useless conversion. + #[allow(clippy::useless_conversion)] + unsafe { ioctl(fd, TIOCSWINSZ.into(), &winsize) }; } /// Handle some signals for the child process. This will loop until the child From f91f446823745927d8f8af195fa4c74685393b94 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Sat, 29 May 2021 15:31:04 +0200 Subject: [PATCH 4/9] Fix cargo fmt diff. --- zellij-server/src/os_input_output.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zellij-server/src/os_input_output.rs b/zellij-server/src/os_input_output.rs index 91a228e7..a104dda2 100644 --- a/zellij-server/src/os_input_output.rs +++ b/zellij-server/src/os_input_output.rs @@ -45,7 +45,9 @@ pub(crate) fn set_terminal_size_using_fd(fd: RawFd, columns: u16, rows: u16) { // some platforms. When checked on Linux, clippy will complain about // useless conversion. #[allow(clippy::useless_conversion)] - unsafe { ioctl(fd, TIOCSWINSZ.into(), &winsize) }; + unsafe { + ioctl(fd, TIOCSWINSZ.into(), &winsize) + }; } /// Handle some signals for the child process. This will loop until the child From 161d78c353dae7449e14f851de9ce4dcb91081de Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Sat, 29 May 2021 21:22:18 +0530 Subject: [PATCH 5/9] session mode should be disabled in locked mode --- default-plugins/status-bar/src/first_line.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default-plugins/status-bar/src/first_line.rs b/default-plugins/status-bar/src/first_line.rs index 7a678cdc..70633195 100644 --- a/default-plugins/status-bar/src/first_line.rs +++ b/default-plugins/status-bar/src/first_line.rs @@ -254,7 +254,7 @@ pub fn ctrl_keys(help: &ModeInfo, max_len: usize, separator: &str) -> LinePart { CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Tab), CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Resize), CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Scroll), - CtrlKeyShortcut::new(CtrlKeyMode::Unselected, CtrlKeyAction::Session), + CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Session), CtrlKeyShortcut::new(CtrlKeyMode::Disabled, CtrlKeyAction::Quit), ], colored_elements, From ef7424d90661310c9d3a375b01bb1b7b573e4089 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Sat, 29 May 2021 21:43:04 +0530 Subject: [PATCH 6/9] docs(changelog): add #547 and #548 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b2508fe..71ad3410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * Fix crash when padding before widechar (https://github.com/zellij-org/zellij/pull/540) * Do not lag when reading input too fast (https://github.com/zellij-org/zellij/pull/536) * Session name optional in attach command (https://github.com/zellij-org/zellij/pull/542) +* Fix build on platforms with TIOCGWINSZ / ioctl() integer type mismatch (https://github.com/zellij-org/zellij/pull/547) +* Fix(ui): session mode should be disabled in locked mode (https://github.com/zellij-org/zellij/pull/548) ## [0.12.1] - 2021-05-28 * HOTFIX: fix Zellij not responding to input on certain terminals (https://github.com/zellij-org/zellij/issues/538) From 154ed3d41cc863e0e4446309db38f8b3aa4479a6 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Sat, 29 May 2021 18:19:34 +0200 Subject: [PATCH 7/9] docs(changelog): Add default_mode option --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71ad3410..1c49de53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * Session name optional in attach command (https://github.com/zellij-org/zellij/pull/542) * Fix build on platforms with TIOCGWINSZ / ioctl() integer type mismatch (https://github.com/zellij-org/zellij/pull/547) * Fix(ui): session mode should be disabled in locked mode (https://github.com/zellij-org/zellij/pull/548) +* Add option to start in arbitrary modes (https://github.com/zellij-org/zellij/pull/513) ## [0.12.1] - 2021-05-28 * HOTFIX: fix Zellij not responding to input on certain terminals (https://github.com/zellij-org/zellij/issues/538) From 70d9d2cf4f49a35f8ac5a4dd1b3e8c88da3981a6 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Sat, 29 May 2021 19:08:36 +0200 Subject: [PATCH 8/9] Add default_mode to attach * Attaching a new session now also respects the default_mode setting of the client --- src/main.rs | 6 +++++- zellij-client/src/lib.rs | 6 +++--- zellij-server/src/lib.rs | 13 +++++++------ zellij-server/src/route.rs | 2 +- zellij-utils/src/ipc.rs | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index b9147fab..97ad3dee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ use zellij_utils::{ cli::{CliArgs, Command, Sessions}, consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR}, input::config::Config, + input::options::Options, logging::*, setup::{get_default_data_dir, Setup}, structopt::StructOpt, @@ -63,11 +64,14 @@ pub fn main() { } else { session_name = Some(get_active_session()); } + + let config_options = Options::from_cli(&config.options, opts.command.clone()); + start_client( Box::new(os_input), opts, config, - ClientInfo::Attach(session_name.unwrap(), force), + ClientInfo::Attach(session_name.unwrap(), force, config_options), ); } else { let session_name = opts diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index 70104784..bd46c90b 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -77,7 +77,7 @@ fn spawn_server(socket_path: &Path) -> io::Result<()> { #[derive(Debug, Clone)] pub enum ClientInfo { - Attach(String, bool), + Attach(String, bool, Options), New(String), } @@ -112,11 +112,11 @@ pub fn start_client( #[cfg(not(any(feature = "test", test)))] let first_msg = match info { - ClientInfo::Attach(name, force) => { + ClientInfo::Attach(name, force, config_options) => { SESSION_NAME.set(name).unwrap(); std::env::set_var(&"ZELLIJ_SESSION_NAME", SESSION_NAME.get().unwrap()); - ClientToServerMsg::AttachClient(client_attributes, force) + ClientToServerMsg::AttachClient(client_attributes, force, config_options) } ClientInfo::New(name) => { SESSION_NAME.set(name).unwrap(); diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index b4036200..76b4b7b1 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -15,7 +15,7 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex, RwLock}; use std::thread; use wasmer::Store; -use zellij_tile::data::{Event, InputMode, PluginCapabilities}; +use zellij_tile::data::{Event, PluginCapabilities}; use crate::{ os_input_output::ServerOsApi, @@ -44,7 +44,7 @@ pub(crate) enum ServerInstruction { ClientExit, Error(String), DetachSession, - AttachClient(ClientAttributes, bool), + AttachClient(ClientAttributes, bool, Options), } impl From for ServerInstruction { @@ -53,8 +53,8 @@ impl From for ServerInstruction { ClientToServerMsg::NewClient(attrs, opts, options) => { ServerInstruction::NewClient(attrs, opts, options) } - ClientToServerMsg::AttachClient(attrs, force) => { - ServerInstruction::AttachClient(attrs, force) + ClientToServerMsg::AttachClient(attrs, force, options) => { + ServerInstruction::AttachClient(attrs, force, options) } _ => unreachable!(), } @@ -225,7 +225,7 @@ pub fn start_server(os_input: Box, socket_path: PathBuf) { .send_to_pty(PtyInstruction::NewTab) .unwrap(); } - ServerInstruction::AttachClient(attrs, _) => { + ServerInstruction::AttachClient(attrs, _, options) => { *session_state.write().unwrap() = SessionState::Attached; let rlock = session_data.read().unwrap(); let session_data = rlock.as_ref().unwrap(); @@ -233,8 +233,9 @@ pub fn start_server(os_input: Box, socket_path: PathBuf) { .senders .send_to_screen(ScreenInstruction::TerminalResize(attrs.position_and_size)) .unwrap(); + let default_mode = options.default_mode.unwrap_or_default(); let mode_info = - get_mode_info(InputMode::Normal, attrs.palette, session_data.capabilities); + get_mode_info(default_mode, attrs.palette, session_data.capabilities); session_data .senders .send_to_screen(ScreenInstruction::ChangeMode(mode_info.clone())) diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 8dcd98ff..673f563a 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -238,7 +238,7 @@ pub(crate) fn route_thread_main( to_server.send(instruction.into()).unwrap(); } } - ClientToServerMsg::AttachClient(_, force) => { + ClientToServerMsg::AttachClient(_, force, _) => { if *session_state.read().unwrap() == SessionState::Attached && !force { os_input.send_to_temp_client(ServerToClientMsg::Exit(ExitReason::CannotAttach)); } else { diff --git a/zellij-utils/src/ipc.rs b/zellij-utils/src/ipc.rs index a160b782..3d75f8a7 100644 --- a/zellij-utils/src/ipc.rs +++ b/zellij-utils/src/ipc.rs @@ -57,7 +57,7 @@ pub enum ClientToServerMsg { DisconnectFromSession,*/ TerminalResize(PositionAndSize), NewClient(ClientAttributes, Box, Box), - AttachClient(ClientAttributes, bool), + AttachClient(ClientAttributes, bool, Options), Action(Action), ClientExited, } From fe299325eb54e6642d27a417a3922a757b4390e4 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Sat, 29 May 2021 20:55:03 +0200 Subject: [PATCH 9/9] docs(changelog): Add default_mode to attach 549 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c49de53..ae5491b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * Fix build on platforms with TIOCGWINSZ / ioctl() integer type mismatch (https://github.com/zellij-org/zellij/pull/547) * Fix(ui): session mode should be disabled in locked mode (https://github.com/zellij-org/zellij/pull/548) * Add option to start in arbitrary modes (https://github.com/zellij-org/zellij/pull/513) +* Attaching to a session respects the `default_mode` setting of the client (https://github.com/zellij-org/zellij/pull/549) ## [0.12.1] - 2021-05-28 * HOTFIX: fix Zellij not responding to input on certain terminals (https://github.com/zellij-org/zellij/issues/538)