|
|
@ -11,13 +11,16 @@ use nvim_rs::{create::tokio as create, UiAttachOptions};
|
|
|
|
use tokio::runtime::Runtime;
|
|
|
|
use tokio::runtime::Runtime;
|
|
|
|
use tokio::process::Command;
|
|
|
|
use tokio::process::Command;
|
|
|
|
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
|
|
|
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
|
|
|
|
|
|
|
use log::{info, error, trace};
|
|
|
|
|
|
|
|
|
|
|
|
pub use events::*;
|
|
|
|
pub use events::*;
|
|
|
|
pub use keybindings::*;
|
|
|
|
pub use keybindings::*;
|
|
|
|
pub use ui_commands::UiCommand;
|
|
|
|
pub use ui_commands::UiCommand;
|
|
|
|
|
|
|
|
use handler::NeovimHandler;
|
|
|
|
use crate::error_handling::ResultPanicExplanation;
|
|
|
|
use crate::error_handling::ResultPanicExplanation;
|
|
|
|
|
|
|
|
use crate::settings::SETTINGS;
|
|
|
|
use crate::INITIAL_DIMENSIONS;
|
|
|
|
use crate::INITIAL_DIMENSIONS;
|
|
|
|
use handler::NeovimHandler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
lazy_static! {
|
|
|
|
pub static ref BRIDGE: Bridge = Bridge::new();
|
|
|
|
pub static ref BRIDGE: Bridge = Bridge::new();
|
|
|
@ -31,8 +34,10 @@ fn set_windows_creation_flags(cmd: &mut Command) {
|
|
|
|
fn create_nvim_command() -> Command {
|
|
|
|
fn create_nvim_command() -> Command {
|
|
|
|
let mut cmd = Command::new("nvim");
|
|
|
|
let mut cmd = Command::new("nvim");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let args = SETTINGS.neovim_arguments.swap(None).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
cmd.arg("--embed")
|
|
|
|
cmd.arg("--embed")
|
|
|
|
.args(std::env::args().skip(1))
|
|
|
|
.args(args.iter().skip(1))
|
|
|
|
.stderr(Stdio::inherit());
|
|
|
|
.stderr(Stdio::inherit());
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
@ -56,14 +61,15 @@ async fn drain(receiver: &mut UnboundedReceiver<UiCommand>) -> Option<Vec<UiComm
|
|
|
|
async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
|
|
|
|
async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
|
|
|
|
let (width, height) = INITIAL_DIMENSIONS;
|
|
|
|
let (width, height) = INITIAL_DIMENSIONS;
|
|
|
|
let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler::new()).await
|
|
|
|
let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler::new()).await
|
|
|
|
.unwrap_or_explained_panic("Could not create nvim process", "Could not locate or start the neovim process");
|
|
|
|
.unwrap_or_explained_panic("Could not locate or start the neovim process");
|
|
|
|
|
|
|
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
|
|
|
info!("Close watcher started");
|
|
|
|
match io_handler.await {
|
|
|
|
match io_handler.await {
|
|
|
|
Err(join_error) => eprintln!("Error joining IO loop: '{}'", join_error),
|
|
|
|
Err(join_error) => eprintln!("Error joining IO loop: '{}'", join_error),
|
|
|
|
Ok(Err(error)) => {
|
|
|
|
Ok(Err(error)) => {
|
|
|
|
if !error.is_channel_closed() {
|
|
|
|
if !error.is_channel_closed() {
|
|
|
|
eprintln!("Error: '{}'", error);
|
|
|
|
error!("Error: '{}'", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ok(Ok(())) => {}
|
|
|
|
Ok(Ok(())) => {}
|
|
|
@ -73,24 +79,26 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
|
|
|
|
|
|
|
|
|
|
|
|
if let Ok(Value::Integer(correct_version)) = nvim.eval("has(\"nvim-0.4\")").await {
|
|
|
|
if let Ok(Value::Integer(correct_version)) = nvim.eval("has(\"nvim-0.4\")").await {
|
|
|
|
if correct_version.as_i64() != Some(1) {
|
|
|
|
if correct_version.as_i64() != Some(1) {
|
|
|
|
println!("Neovide requires version 0.4 or higher");
|
|
|
|
error!("Neovide requires version 0.4 or higher");
|
|
|
|
std::process::exit(0);
|
|
|
|
std::process::exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
println!("Neovide requires version 0.4 or higher");
|
|
|
|
error!("Neovide requires version 0.4 or higher");
|
|
|
|
std::process::exit(0);
|
|
|
|
std::process::exit(0);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nvim.set_var("neovide", Value::Boolean(true)).await
|
|
|
|
nvim.set_var("neovide", Value::Boolean(true)).await
|
|
|
|
.unwrap_or_explained_panic("Could not communicate.", "Could not communicate with neovim process");
|
|
|
|
.unwrap_or_explained_panic("Could not communicate with neovim process");
|
|
|
|
let mut options = UiAttachOptions::new();
|
|
|
|
let mut options = UiAttachOptions::new();
|
|
|
|
options.set_linegrid_external(true);
|
|
|
|
options.set_linegrid_external(true);
|
|
|
|
options.set_rgb(true);
|
|
|
|
options.set_rgb(true);
|
|
|
|
nvim.ui_attach(width as i64, height as i64, &options).await
|
|
|
|
nvim.ui_attach(width as i64, height as i64, &options).await
|
|
|
|
.unwrap_or_explained_panic("Could not attach.", "Could not attach ui to neovim process");
|
|
|
|
.unwrap_or_explained_panic("Could not attach ui to neovim process");
|
|
|
|
|
|
|
|
info!("Neovim process attached");
|
|
|
|
|
|
|
|
|
|
|
|
let nvim = Arc::new(nvim);
|
|
|
|
let nvim = Arc::new(nvim);
|
|
|
|
tokio::spawn(async move {
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
|
|
|
info!("UiCommand processor started");
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
if let Some(commands) = drain(&mut receiver).await {
|
|
|
|
if let Some(commands) = drain(&mut receiver).await {
|
|
|
|
let (resize_list, other_commands): (Vec<UiCommand>, Vec<UiCommand>) = commands
|
|
|
|
let (resize_list, other_commands): (Vec<UiCommand>, Vec<UiCommand>) = commands
|
|
|
@ -103,6 +111,7 @@ async fn start_process(mut receiver: UnboundedReceiver<UiCommand>) {
|
|
|
|
|
|
|
|
|
|
|
|
let nvim = nvim.clone();
|
|
|
|
let nvim = nvim.clone();
|
|
|
|
tokio::spawn(async move {
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
|
|
|
trace!("Executing UiCommand: {:?}", &command);
|
|
|
|
command.execute(&nvim).await;
|
|
|
|
command.execute(&nvim).await;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -131,9 +140,9 @@ impl Bridge {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn queue_command(&self, command: UiCommand) {
|
|
|
|
pub fn queue_command(&self, command: UiCommand) {
|
|
|
|
|
|
|
|
trace!("UiCommand queued: {:?}", &command);
|
|
|
|
self.sender.send(command)
|
|
|
|
self.sender.send(command)
|
|
|
|
.unwrap_or_explained_panic(
|
|
|
|
.unwrap_or_explained_panic(
|
|
|
|
"Could Not Send UI Command",
|
|
|
|
|
|
|
|
"Could not send UI command from the window system to the neovim process.");
|
|
|
|
"Could not send UI command from the window system to the neovim process.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|