summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-05-29 18:18:30 +0200
committerGitHub <noreply@github.com>2021-05-29 18:18:30 +0200
commit4c079ca25d0d4ebbfbe48f30ff787ebd2864bdf7 (patch)
tree7cfde72edb544a450bae4afdc5d4485783f33366
parentef7424d90661310c9d3a375b01bb1b7b573e4089 (diff)
parentec5476d3a593e20f11a898338a941fb90e0cab1b (diff)
Merge pull request #513 from a-kenji/default-mode-368
Default mode 368
-rw-r--r--zellij-client/src/input_handler.rs5
-rw-r--r--zellij-client/src/lib.rs10
-rw-r--r--zellij-server/src/screen.rs4
-rw-r--r--zellij-tile/src/data.rs18
-rw-r--r--zellij-utils/src/input/options.rs14
5 files changed, 46 insertions, 5 deletions
diff --git a/zellij-client/src/input_handler.rs b/zellij-client/src/input_handler.rs
index 70f6e9824..65181e512 100644
--- a/zellij-client/src/input_handler.rs
+++ b/zellij-client/src/input_handler.rs
@@ -33,9 +33,10 @@ impl InputHandler {
command_is_executing: CommandIsExecuting,
config: Config,
send_client_instructions: SenderWithContext<ClientInstruction>,
+ mode: InputMode,
) -> Self {
InputHandler {
- mode: InputMode::Normal,
+ mode,
os_input,
config,
command_is_executing,
@@ -181,12 +182,14 @@ pub(crate) fn input_loop(
config: Config,
command_is_executing: CommandIsExecuting,
send_client_instructions: SenderWithContext<ClientInstruction>,
+ default_mode: InputMode,
) {
let _handler = InputHandler::new(
os_input,
command_is_executing,
config,
send_client_instructions,
+ default_mode,
)
.handle_input();
}
diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs
index 3817e7908..701047842 100644
--- a/zellij-client/src/lib.rs
+++ b/zellij-client/src/lib.rs
@@ -127,14 +127,18 @@ pub fn start_client(
ClientToServerMsg::NewClient(
client_attributes,
Box::new(opts),
- Box::new(config_options),
+ Box::new(config_options.clone()),
)
}
};
#[cfg(any(feature = "test", test))]
let first_msg = {
let _ = SESSION_NAME.set("".into());
- ClientToServerMsg::NewClient(client_attributes, Box::new(opts), Box::new(config_options))
+ ClientToServerMsg::NewClient(
+ client_attributes,
+ Box::new(opts),
+ Box::new(config_options.clone()),
+ )
};
os_input.connect_to_server(&*ZELLIJ_IPC_PIPE);
@@ -168,12 +172,14 @@ pub fn start_client(
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_default();
move || {
input_loop(
os_input,
config,
command_is_executing,
send_client_instructions,
+ default_mode,
)
}
});
diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs
index 068037eea..48be44bfc 100644
--- a/zellij-server/src/screen.rs
+++ b/zellij-server/src/screen.rs
@@ -405,6 +405,7 @@ pub(crate) fn screen_thread_main(
session_state: Arc<RwLock<SessionState>>,
) {
let capabilities = config_options.simplified_ui;
+ let default_mode = config_options.default_mode.unwrap_or_default();
let mut screen = Screen::new(
bus,
@@ -415,9 +416,10 @@ pub(crate) fn screen_thread_main(
capabilities: PluginCapabilities {
arrow_fonts: capabilities,
},
+ mode: default_mode,
..ModeInfo::default()
},
- InputMode::Normal,
+ default_mode,
session_state,
);
loop {
diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs
index cb4b2aa01..3bd926ca6 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)]
@@ -92,6 +93,23 @@ impl Default for PaletteColor {
}
}
+impl FromStr for InputMode {
+ type Err = Box<dyn std::error::Error>;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ 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,
diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs
index f9724c20f..3476c2fb9 100644
--- a/zellij-utils/src/input/options.rs
+++ b/zellij-utils/src/input/options.rs
@@ -2,6 +2,7 @@
use crate::cli::Command;
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<InputMode>,
}
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<Command>) -> Options {