Skip to content

Commit

Permalink
Merge pull request #609 from zellij-org/force-close
Browse files Browse the repository at this point in the history
Add on_force_close config option
  • Loading branch information
kunalmohan authored Jul 9, 2021
2 parents 50d049a + 56af1d8 commit 0e6e581
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
4 changes: 3 additions & 1 deletion zellij-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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()));
}
}),
);
Expand Down
7 changes: 7 additions & 0 deletions zellij-utils/assets/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions zellij-utils/src/input/actions.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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,
}
}
}
34 changes: 34 additions & 0 deletions zellij-utils/src/input/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +55,9 @@ pub struct Options {
#[structopt(long)]
#[serde(default)]
pub disable_mouse_mode: bool,
/// Set behaviour on force close (quit or detach)
#[structopt(long)]
pub on_force_close: Option<OnForceClose>,
}

impl Options {
Expand Down Expand Up @@ -77,13 +105,19 @@ 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,
default_mode,
default_shell,
layout_dir,
disable_mouse_mode,
on_force_close,
}
}

Expand Down

0 comments on commit 0e6e581

Please sign in to comment.