aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-07-09 00:25:59 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-07-09 00:36:47 +0530
commit67ee63548aa48caebf32b081d57cb8184bff39b8 (patch)
tree270873d4947ac83b2b51876a2dabc17f8b9a6ff0
parentdocs(changelog): Change Run binding #602 (diff)
downloadsl0ppij-67ee63548aa48caebf32b081d57cb8184bff39b8.tar.gz
sl0ppij-67ee63548aa48caebf32b081d57cb8184bff39b8.tar.xz
sl0ppij-67ee63548aa48caebf32b081d57cb8184bff39b8.zip
Add on_force_close config option
-rw-r--r--zellij-client/src/lib.rs4
-rw-r--r--zellij-utils/assets/config/default.yaml7
-rw-r--r--zellij-utils/src/input/actions.rs10
-rw-r--r--zellij-utils/src/input/options.rs33
4 files changed, 53 insertions, 1 deletions
diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs
index 90732024..2bfaae2e 100644
--- a/zellij-client/src/lib.rs
+++ b/zellij-client/src/lib.rs
@@ -164,6 +164,8 @@ pub fn start_client(
})
});
+ let on_force_close = config_options.on_force_close.unwrap_or_default();
+
let _stdin_thread = thread::Builder::new()
.name("stdin_handler".to_string())
.spawn({
@@ -200,7 +202,7 @@ pub fn start_client(
Box::new({
let os_api = os_input.clone();
move || {
- os_api.send_to_server(ClientToServerMsg::Action(Action::Detach));
+ os_api.send_to_server(ClientToServerMsg::Action(on_force_close.into()));
}
}),
);
diff --git a/zellij-utils/assets/config/default.yaml b/zellij-utils/assets/config/default.yaml
index 42bc1688..9b0a57ff 100644
--- a/zellij-utils/assets/config/default.yaml
+++ b/zellij-utils/assets/config/default.yaml
@@ -240,3 +240,10 @@ keybinds:
key: [Ctrl: 'q',]
- action: [Detach,]
key: [Char: 'd',]
+
+# Choose what to do when zellij receives SIGTERM, SIGINT, SIGQUIT or SIGHUP
+# eg. when terminal window with an active zellij session is closed
+# Options:
+# - Detach (Default)
+# - Quit
+#on_force_close: Quit
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs
index ecd515a4..bfd7d255 100644
--- a/zellij-utils/src/input/actions.rs
+++ b/zellij-utils/src/input/actions.rs
@@ -1,6 +1,7 @@
//! Definition of the actions that can be bound to keys.
use super::command::RunCommandAction;
+use crate::input::options::OnForceClose;
use serde::{Deserialize, Serialize};
use zellij_tile::data::InputMode;
@@ -81,3 +82,12 @@ pub enum Action {
MouseHold(Position),
Copy,
}
+
+impl From<OnForceClose> for Action {
+ fn from(ofc: OnForceClose) -> Action {
+ match ofc {
+ OnForceClose::Quit => Action::Quit,
+ OnForceClose::Detach => Action::Detach,
+ }
+ }
+}
diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs
index 2ba2be86..c2083f4e 100644
--- a/zellij-utils/src/input/options.rs
+++ b/zellij-utils/src/input/options.rs
@@ -2,9 +2,34 @@
use crate::cli::Command;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
+use std::str::FromStr;
use structopt::StructOpt;
use zellij_tile::data::InputMode;
+#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)]
+pub enum OnForceClose {
+ Quit,
+ Detach,
+}
+
+impl Default for OnForceClose {
+ fn default() -> Self {
+ Self::Detach
+ }
+}
+
+impl FromStr for OnForceClose {
+ type Err = Box<dyn std::error::Error>;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "quit" => Ok(Self::Quit),
+ "detach" => Ok(Self::Detach),
+ e => Err(e.to_string().into()),
+ }
+ }
+}
+
#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, StructOpt)]
/// Options that can be set either through the config file,
/// or cli flags
@@ -30,6 +55,8 @@ pub struct Options {
#[structopt(long)]
#[serde(default)]
pub disable_mouse_mode: bool,
+ #[structopt(long)]
+ pub on_force_close: Option<OnForceClose>,
}
impl Options {
@@ -77,6 +104,11 @@ impl Options {
self.disable_mouse_mode
};
+ let on_force_close = match other.on_force_close {
+ None => self.on_force_close,
+ other => other,
+ };
+
Options {
simplified_ui,
theme,
@@ -84,6 +116,7 @@ impl Options {
default_shell,
layout_dir,
disable_mouse_mode,
+ on_force_close,
}
}