feat(ipc): send external ipc messages to active session through cli

This commit is contained in:
Aram Drevekenin 2020-10-21 09:24:31 +02:00
parent bd5824ce3f
commit 3ea03edfdd
3 changed files with 171 additions and 2 deletions

126
Cargo.lock generated
View file

@ -1,5 +1,14 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # 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]] [[package]]
name = "arc-swap" name = "arc-swap"
version = "0.4.7" version = "0.4.7"
@ -59,6 +68,17 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" 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]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.0.0" version = "1.0.0"
@ -125,6 +145,21 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 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]] [[package]]
name = "concurrent-queue" name = "concurrent-queue"
version = "1.2.0" version = "1.2.0"
@ -322,6 +357,15 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
dependencies = [
"unicode-segmentation",
]
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.15" version = "0.1.15"
@ -414,6 +458,7 @@ dependencies = [
"nix", "nix",
"serde", "serde",
"signal-hook", "signal-hook",
"structopt",
"termios", "termios",
"unicode-truncate", "unicode-truncate",
"unicode-width", "unicode-width",
@ -487,6 +532,30 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 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]] [[package]]
name = "proc-macro-hack" name = "proc-macro-hack"
version = "0.5.18" version = "0.5.18"
@ -643,6 +712,36 @@ dependencies = [
"winapi", "winapi",
] ]
[[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]] [[package]]
name = "syn" name = "syn"
version = "1.0.36" version = "1.0.36"
@ -673,6 +772,21 @@ dependencies = [
"libc", "libc",
] ]
[[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]] [[package]]
name = "unicode-truncate" name = "unicode-truncate"
version = "0.1.1" version = "0.1.1"
@ -700,6 +814,18 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372" 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]] [[package]]
name = "void" name = "void"
version = "1.0.2" version = "1.0.2"

View file

@ -17,6 +17,7 @@ vte = "0.8.0"
futures = "0.3.5" futures = "0.3.5"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
bincode = "1.3.1" bincode = "1.3.1"
structopt = "0.3"
[dependencies.async-std] [dependencies.async-std]
version = "1.3.0" version = "1.3.0"

View file

@ -21,6 +21,8 @@ use crate::screen::{Screen, ScreenInstruction};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::fs::remove_file; use std::fs::remove_file;
use structopt::StructOpt;
// sigwinch stuff // sigwinch stuff
use ::signal_hook::iterator::Signals; use ::signal_hook::iterator::Signals;
@ -29,12 +31,26 @@ pub type SigCleanup = dyn Fn() + Send;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
enum ApiCommand { enum ApiCommand {
OpenFile(String), OpenFile(PathBuf),
SplitHorizontally, SplitHorizontally,
SplitVertically, SplitVertically,
MoveFocus, 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) { fn debug_log_to_file (message: String) {
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::prelude::*; use std::io::prelude::*;
@ -64,8 +80,34 @@ pub fn sigwinch() -> (Box<OnSigWinch>, Box<SigCleanup>) {
pub fn main() { pub fn main() {
let os_input = get_os_input(); let os_input = get_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)); start(Box::new(os_input));
} }
}
pub fn start(mut os_input: Box<dyn OsApi>) { pub fn start(mut os_input: Box<dyn OsApi>) {
let mut active_threads = vec![]; let mut active_threads = vec![];