clean and exit on window close
This commit is contained in:
parent
07ca0cbb11
commit
050d846b5e
5 changed files with 29 additions and 24 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -3,4 +3,5 @@
|
||||||
.vscode
|
.vscode
|
||||||
.vim
|
.vim
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/assets/man/zellij.1
|
/assets/man/zellij.1
|
||||||
|
**/target
|
||||||
|
|
@ -132,15 +132,26 @@ pub fn start_client(mut os_input: Box<dyn ClientOsApi>, opts: CliArgs, config: C
|
||||||
.name("signal_listener".to_string())
|
.name("signal_listener".to_string())
|
||||||
.spawn({
|
.spawn({
|
||||||
let os_input = os_input.clone();
|
let os_input = os_input.clone();
|
||||||
|
let send_client_instructions = send_client_instructions.clone();
|
||||||
move || {
|
move || {
|
||||||
os_input.receive_sigwinch(Box::new({
|
os_input.handle_signals(
|
||||||
let os_api = os_input.clone();
|
Box::new({
|
||||||
move || {
|
let os_api = os_input.clone();
|
||||||
os_api.send_to_server(ClientToServerMsg::TerminalResize(
|
move || {
|
||||||
os_api.get_terminal_size_using_fd(0),
|
os_api.send_to_server(ClientToServerMsg::TerminalResize(
|
||||||
));
|
os_api.get_terminal_size_using_fd(0),
|
||||||
}
|
));
|
||||||
}));
|
}
|
||||||
|
}),
|
||||||
|
Box::new({
|
||||||
|
let send_client_instructions = send_client_instructions.clone();
|
||||||
|
move || {
|
||||||
|
send_client_instructions
|
||||||
|
.send(ClientInstruction::Exit)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
|
|
@ -314,7 +314,7 @@ pub trait ClientOsApi: Send + Sync {
|
||||||
/// Receives a message on client-side IPC channel
|
/// Receives a message on client-side IPC channel
|
||||||
// This should be called from the client-side router thread only.
|
// This should be called from the client-side router thread only.
|
||||||
fn recv_from_server(&self) -> (ServerToClientMsg, ErrorContext);
|
fn recv_from_server(&self) -> (ServerToClientMsg, ErrorContext);
|
||||||
fn receive_sigwinch(&self, cb: Box<dyn Fn()>);
|
fn handle_signals(&self, sigwinch_cb: Box<dyn Fn()>, quit_cb: Box<dyn Fn()>);
|
||||||
/// Establish a connection with the server socket.
|
/// Establish a connection with the server socket.
|
||||||
fn connect_to_server(&self, path: &Path);
|
fn connect_to_server(&self, path: &Path);
|
||||||
}
|
}
|
||||||
|
|
@ -362,14 +362,15 @@ impl ClientOsApi for ClientOsInputOutput {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.recv()
|
.recv()
|
||||||
}
|
}
|
||||||
fn receive_sigwinch(&self, cb: Box<dyn Fn()>) {
|
fn handle_signals(&self, sigwinch_cb: Box<dyn Fn()>, quit_cb: Box<dyn Fn()>) {
|
||||||
let mut signals = Signals::new(&[SIGWINCH, SIGTERM, SIGINT, SIGQUIT]).unwrap();
|
let mut signals = Signals::new(&[SIGWINCH, SIGTERM, SIGINT, SIGQUIT, SIGHUP]).unwrap();
|
||||||
for signal in signals.forever() {
|
for signal in signals.forever() {
|
||||||
match signal {
|
match signal {
|
||||||
SIGWINCH => {
|
SIGWINCH => {
|
||||||
cb();
|
sigwinch_cb();
|
||||||
}
|
}
|
||||||
SIGTERM | SIGINT | SIGQUIT => {
|
SIGTERM | SIGINT | SIGQUIT | SIGHUP => {
|
||||||
|
quit_cb();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,6 @@ use std::convert::TryFrom;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let opts = CliArgs::from_args();
|
let opts = CliArgs::from_args();
|
||||||
let config = match Config::try_from(&opts) {
|
|
||||||
Ok(config) => config,
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("There was an error in the config file:\n{}", e);
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(crate::cli::ConfigCli::Setup(setup)) = opts.option.clone() {
|
if let Some(crate::cli::ConfigCli::Setup(setup)) = opts.option.clone() {
|
||||||
Setup::from_cli(&setup, opts).expect("Failed to print to stdout");
|
Setup::from_cli(&setup, opts).expect("Failed to print to stdout");
|
||||||
|
|
@ -43,7 +36,6 @@ pub fn main() {
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let config_options = Options::from_cli(&config.options, opts.option.clone());
|
|
||||||
atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap();
|
atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap();
|
||||||
atomic_create_dir(&*ZELLIJ_TMP_LOG_DIR).unwrap();
|
atomic_create_dir(&*ZELLIJ_TMP_LOG_DIR).unwrap();
|
||||||
if let Some(path) = opts.server {
|
if let Some(path) = opts.server {
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ impl ClientOsApi for FakeInputOutput {
|
||||||
.recv()
|
.recv()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
fn receive_sigwinch(&self, cb: Box<dyn Fn()>) {
|
fn handle_signals(&self, sigwinch_cb: Box<dyn Fn()>, _quit_cb: Box<dyn Fn()>) {
|
||||||
if self.sigwinch_event.is_some() {
|
if self.sigwinch_event.is_some() {
|
||||||
let (lock, cvar) = &*self.should_trigger_sigwinch;
|
let (lock, cvar) = &*self.should_trigger_sigwinch;
|
||||||
{
|
{
|
||||||
|
|
@ -213,7 +213,7 @@ impl ClientOsApi for FakeInputOutput {
|
||||||
should_trigger_sigwinch = cvar.wait(should_trigger_sigwinch).unwrap();
|
should_trigger_sigwinch = cvar.wait(should_trigger_sigwinch).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cb();
|
sigwinch_cb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn connect_to_server(&self, _path: &std::path::Path) {}
|
fn connect_to_server(&self, _path: &std::path::Path) {}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue