aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-02-11 23:07:54 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-05-04 20:47:48 +0530
commit685e2eef0ca340f48f5125a13918ca30656aabd5 (patch)
tree43a6486fa4041dd5acf2ee4d6069be3a545eeae2 /src/main.rs
parentremove debug logs (diff)
downloadsl0ppij-685e2eef0ca340f48f5125a13918ca30656aabd5.tar.gz
sl0ppij-685e2eef0ca340f48f5125a13918ca30656aabd5.tar.xz
sl0ppij-685e2eef0ca340f48f5125a13918ca30656aabd5.zip
Introduce IpcSenderWithContext
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs84
1 files changed, 47 insertions, 37 deletions
diff --git a/src/main.rs b/src/main.rs
index 5fa9317e..11355fbb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,12 +3,20 @@ mod client;
mod common;
mod server;
+use client::{boundaries, layout, panes, tab};
+use common::{
+ command_is_executing, errors, ipc, os_input_output, pty_bus, screen, start, utils, wasm_vm,
+ ApiCommand, IpcSenderWithContext,
+};
+use directories_next::ProjectDirs;
+
+use structopt::StructOpt;
+
use crate::cli::CliArgs;
use crate::command_is_executing::CommandIsExecuting;
-use crate::errors::ErrorContext;
use crate::os_input_output::get_os_input;
use crate::utils::{
- consts::{ZELLIJ_IPC_PIPE, ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
+ consts::{ZELLIJ_TMP_DIR, ZELLIJ_TMP_LOG_DIR},
logging::*,
};
use client::{boundaries, layout, panes, tab};
@@ -22,6 +30,27 @@ use std::os::unix::net::UnixStream;
use structopt::StructOpt;
pub fn main() {
+ // First run installation of default plugins & layouts
+ let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
+ let data_dir = project_dirs.data_dir();
+ let mut assets = asset_map! {
+ "assets/layouts/default.yaml" => "layouts/default.yaml",
+ "assets/layouts/strider.yaml" => "layouts/strider.yaml",
+ };
+ assets.extend(asset_map! {
+ "assets/plugins/status-bar.wasm" => "plugins/status-bar.wasm",
+ "assets/plugins/tab-bar.wasm" => "plugins/tab-bar.wasm",
+ "assets/plugins/strider.wasm" => "plugins/strider.wasm",
+ });
+
+ for (path, bytes) in assets {
+ let path = data_dir.join(path);
+ std::fs::create_dir_all(path.parent().unwrap()).unwrap();
+ if !path.exists() {
+ std::fs::write(path, bytes).expect("Failed to install default assets!");
+ }
+ }
+
let opts = CliArgs::from_args();
let config = match Config::try_from(&opts) {
Ok(config) => config,
@@ -33,48 +62,29 @@ pub fn main() {
if let Some(split_dir) = opts.split {
match split_dir {
'h' => {
- let mut stream = UnixStream::connect(ZELLIJ_IPC_PIPE).unwrap();
- let api_command =
- bincode::serialize(&(ErrorContext::new(), ApiCommand::SplitHorizontally))
- .unwrap();
- stream.write_all(&api_command).unwrap();
+ let mut send_server_instructions = IpcSenderWithContext::new();
+ send_server_instructions
+ .send(ApiCommand::SplitHorizontally)
+ .unwrap();
}
'v' => {
- let mut stream = UnixStream::connect(ZELLIJ_IPC_PIPE).unwrap();
- let api_command =
- bincode::serialize(&(ErrorContext::new(), ApiCommand::SplitVertically))
- .unwrap();
- stream.write_all(&api_command).unwrap();
+ let mut send_server_instructions = IpcSenderWithContext::new();
+ send_server_instructions
+ .send(ApiCommand::SplitVertically)
+ .unwrap();
}
_ => {}
};
} else if opts.move_focus {
- let mut stream = UnixStream::connect(ZELLIJ_IPC_PIPE).unwrap();
- let api_command =
- bincode::serialize(&(ErrorContext::new(), ApiCommand::MoveFocus)).unwrap();
- stream.write_all(&api_command).unwrap();
+ let mut send_server_instructions = IpcSenderWithContext::new();
+ send_server_instructions
+ .send(ApiCommand::MoveFocus)
+ .unwrap();
} else if let Some(file_to_open) = opts.open_file {
- let mut stream = UnixStream::connect(ZELLIJ_IPC_PIPE).unwrap();
- let api_command =
- bincode::serialize(&(ErrorContext::new(), ApiCommand::OpenFile(file_to_open))).unwrap();
- stream.write_all(&api_command).unwrap();
- } else if let Some(crate::cli::ConfigCli::GenerateCompletion { shell }) = opts.option {
- let shell = match shell.as_ref() {
- "bash" => structopt::clap::Shell::Bash,
- "fish" => structopt::clap::Shell::Fish,
- "zsh" => structopt::clap::Shell::Zsh,
- "powerShell" => structopt::clap::Shell::PowerShell,
- "elvish" => structopt::clap::Shell::Elvish,
- other => {
- eprintln!("Unsupported shell: {}", other);
- std::process::exit(1);
- }
- };
- let mut out = std::io::stdout();
- CliArgs::clap().gen_completions_to("zellij", shell, &mut out);
- } else if let Some(crate::cli::ConfigCli::Setup { .. }) = opts.option {
- setup::dump_default_config().expect("Failed to print to stdout");
- std::process::exit(1);
+ let mut send_server_instructions = IpcSenderWithContext::new();
+ send_server_instructions
+ .send(ApiCommand::OpenFile(file_to_open))
+ .unwrap();
} else {
let os_input = get_os_input();
atomic_create_dir(ZELLIJ_TMP_DIR).unwrap();