aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2020-10-21 09:24:31 +0200
committerAram Drevekenin <aram@poor.dev>2020-10-21 09:24:31 +0200
commit3ea03edfdda142e51010c6133e5ba7f2fbab96c5 (patch)
tree1501de05425544dbf3b4a3fe1702a3c6a2063ba8
parentfeat(ipc): listen to external ipc messages including a basic api (diff)
downloadsl0ppij-3ea03edfdda142e51010c6133e5ba7f2fbab96c5.tar.gz
sl0ppij-3ea03edfdda142e51010c6133e5ba7f2fbab96c5.tar.xz
sl0ppij-3ea03edfdda142e51010c6133e5ba7f2fbab96c5.zip
feat(ipc): send external ipc messages to active session through cli
-rw-r--r--Cargo.lock126
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs46
3 files changed, 171 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f0239832..9667bb05 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,15 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
+name = "ansi_term"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
name = "arc-swap"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -60,6 +69,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi",
+]
+
+[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -126,6 +146,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
+name = "clap"
+version = "2.33.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
+dependencies = [
+ "ansi_term",
+ "atty",
+ "bitflags",
+ "strsim",
+ "textwrap",
+ "unicode-width",
+ "vec_map",
+]
+
+[[package]]
name = "concurrent-queue"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -323,6 +358,15 @@ dependencies = [
]
[[package]]
+name = "heck"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
+dependencies = [
+ "unicode-segmentation",
+]
+
+[[package]]
name = "hermit-abi"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -414,6 +458,7 @@ dependencies = [
"nix",
"serde",
"signal-hook",
+ "structopt",
"termios",
"unicode-truncate",
"unicode-width",
@@ -488,6 +533,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
+[[package]]
name = "proc-macro-hack"
version = "0.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -644,6 +713,36 @@ dependencies = [
]
[[package]]
+name = "strsim"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
+
+[[package]]
+name = "structopt"
+version = "0.3.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "126d630294ec449fae0b16f964e35bf3c74f940da9dca17ee9b905f7b3112eb8"
+dependencies = [
+ "clap",
+ "lazy_static",
+ "structopt-derive",
+]
+
+[[package]]
+name = "structopt-derive"
+version = "0.4.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65e51c492f9e23a220534971ff5afc14037289de430e3c83f9daf6a1b6ae91e8"
+dependencies = [
+ "heck",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "syn"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -674,6 +773,21 @@ dependencies = [
]
[[package]]
+name = "textwrap"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
+dependencies = [
+ "unicode-width",
+]
+
+[[package]]
+name = "unicode-segmentation"
+version = "1.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
+
+[[package]]
name = "unicode-truncate"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -701,6 +815,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
[[package]]
+name = "vec_map"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
+
+[[package]]
+name = "version_check"
+version = "0.9.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
+
+[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 4c35e286..31424fb3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,6 +17,7 @@ vte = "0.8.0"
futures = "0.3.5"
serde = { version = "1.0", features = ["derive"] }
bincode = "1.3.1"
+structopt = "0.3"
[dependencies.async-std]
version = "1.3.0"
diff --git a/src/main.rs b/src/main.rs
index 79609108..7876ed06 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,6 +21,8 @@ use crate::screen::{Screen, ScreenInstruction};
use std::path::{Path, PathBuf};
use std::fs::remove_file;
+use structopt::StructOpt;
+
// sigwinch stuff
use ::signal_hook::iterator::Signals;
@@ -29,12 +31,26 @@ pub type SigCleanup = dyn Fn() + Send;
#[derive(Serialize, Deserialize, Debug)]
enum ApiCommand {
- OpenFile(String),
+ OpenFile(PathBuf),
SplitHorizontally,
SplitVertically,
MoveFocus,
}
+#[derive(StructOpt, Debug)]
+#[structopt(name = "mosaic")]
+pub struct Opt {
+ #[structopt(short, long)]
+ /// Send "split (direction h == horizontal / v == vertical)" to active mosaic session
+ split: Option<char>,
+ #[structopt(short, long)]
+ /// Send "move focused pane" to active mosaic session
+ move_focus: bool,
+ #[structopt(short, long)]
+ /// Send "open file in new pane" to active mosaic session
+ open_file: Option<PathBuf>
+}
+
fn debug_log_to_file (message: String) {
use std::fs::OpenOptions;
use std::io::prelude::*;
@@ -64,7 +80,33 @@ pub fn sigwinch() -> (Box<OnSigWinch>, Box<SigCleanup>) {
pub fn main() {
let os_input = get_os_input();
- start(Box::new(os_input));
+ let opts = Opt::from_args();
+ if opts.split.is_some() {
+ match opts.split {
+ Some('h') => {
+ let mut stream = UnixStream::connect("/tmp/mosaic").unwrap();
+ let api_command = bincode::serialize(&ApiCommand::SplitHorizontally).unwrap();
+ stream.write_all(&api_command).unwrap();
+ },
+ Some('v') => {
+ let mut stream = UnixStream::connect("/tmp/mosaic").unwrap();
+ let api_command = bincode::serialize(&ApiCommand::SplitVertically).unwrap();
+ stream.write_all(&api_command).unwrap();
+ },
+ _ => {}
+ };
+ } else if opts.move_focus {
+ let mut stream = UnixStream::connect("/tmp/mosaic").unwrap();
+ let api_command = bincode::serialize(&ApiCommand::MoveFocus).unwrap();
+ stream.write_all(&api_command).unwrap();
+ } else if opts.open_file.is_some() {
+ let mut stream = UnixStream::connect("/tmp/mosaic").unwrap();
+ let file_to_open = opts.open_file.unwrap();
+ let api_command = bincode::serialize(&ApiCommand::OpenFile(file_to_open)).unwrap();
+ stream.write_all(&api_command).unwrap();
+ } else {
+ start(Box::new(os_input));
+ }
}
pub fn start(mut os_input: Box<dyn OsApi>) {