diff --git a/src/bridge/handler.rs b/src/bridge/handler.rs index c330d28..986bea2 100644 --- a/src/bridge/handler.rs +++ b/src/bridge/handler.rs @@ -1,32 +1,33 @@ use std::sync::Arc; -use std::sync::mpsc::Sender; use async_trait::async_trait; use crossfire::mpsc::TxUnbounded; use log::trace; use nvim_rs::{compat::tokio::Compat, Handler, Neovim}; +use parking_lot::Mutex; use rmpv::Value; -use tokio::sync::mpsc::UnboundedSender; use tokio::process::ChildStdin; use tokio::task; -use parking_lot::Mutex; use super::events::{parse_redraw_event, RedrawEvent}; use super::ui_commands::UiCommand; -use crate::settings::SETTINGS; use crate::error_handling::ResultPanicExplanation; +use crate::settings::SETTINGS; #[derive(Clone)] pub struct NeovimHandler { ui_command_sender: Arc>>, - redraw_event_sender: Arc>> + redraw_event_sender: Arc>>, } impl NeovimHandler { - pub fn new(ui_command_sender: TxUnbounded, redraw_event_sender: TxUnbounded) -> NeovimHandler { + pub fn new( + ui_command_sender: TxUnbounded, + redraw_event_sender: TxUnbounded, + ) -> NeovimHandler { NeovimHandler { ui_command_sender: Arc::new(Mutex::new(ui_command_sender)), - redraw_event_sender: Arc::new(Mutex::new(redraw_event_sender)) + redraw_event_sender: Arc::new(Mutex::new(redraw_event_sender)), } } } diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index 61c221f..2d722e2 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -2,27 +2,21 @@ pub mod layouts; mod events; -mod ui_commands; mod handler; +mod ui_commands; use std::env; use std::path::Path; use std::process::Stdio; use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::mpsc::{Receiver, Sender}; use std::sync::Arc; -use std::thread; - -#[cfg(windows)] -use std::os::windows::process::CommandExt; -use crossfire::mpsc::{TxUnbounded, RxUnbounded}; +use crossfire::mpsc::{RxUnbounded, TxUnbounded}; use log::{error, info, warn}; use nvim_rs::{create::tokio as create, UiAttachOptions}; use rmpv::Value; use tokio::process::Command; use tokio::runtime::Runtime; -use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}; use crate::error_handling::ResultPanicExplanation; use crate::settings::*; @@ -122,10 +116,9 @@ async fn start_neovim_runtime( ) { let (width, height) = window_geometry_or_default(); let handler = NeovimHandler::new(ui_command_sender.clone(), redraw_event_sender.clone()); - let (mut nvim, io_handler, _) = - create::new_child_cmd(&mut create_nvim_command(), handler) - .await - .unwrap_or_explained_panic("Could not locate or start neovim process"); + let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), handler) + .await + .unwrap_or_explained_panic("Could not locate or start neovim process"); if nvim.get_api_info().await.is_err() { error!("Cannot get neovim api info, either neovide is launched with an unknown command line option or neovim version not supported!"); @@ -231,7 +224,9 @@ async fn start_neovim_runtime( let mut options = UiAttachOptions::new(); options.set_linegrid_external(true); - options.set_multigrid_external(true); + if env::args().any(|arg| arg == "--multiGrid") || env::var("NeovideMultiGrid").is_ok() { + options.set_multigrid_external(true); + } options.set_rgb(true); nvim.ui_attach(width as i64, height as i64, &options) .await @@ -276,11 +271,14 @@ pub fn start_bridge( ui_command_sender: TxUnbounded, ui_command_receiver: RxUnbounded, redraw_event_sender: TxUnbounded, - running: Arc + running: Arc, ) -> Bridge { let runtime = Runtime::new().unwrap(); - runtime.spawn(start_neovim_runtime(ui_command_sender, ui_command_receiver, redraw_event_sender, running)); - Bridge { - _runtime: runtime - } + runtime.spawn(start_neovim_runtime( + ui_command_sender, + ui_command_receiver, + redraw_event_sender, + running, + )); + Bridge { _runtime: runtime } } diff --git a/src/editor/mod.rs b/src/editor/mod.rs index d644650..3a0d90c 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -6,7 +6,7 @@ mod window; use std::collections::HashMap; use std::fmt; -use std::sync::mpsc::{Receiver, Sender}; +use std::sync::mpsc::Sender; use std::sync::Arc; use std::thread; diff --git a/src/main.rs b/src/main.rs index 62d5fb4..65ac6e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,9 +18,9 @@ extern crate rust_embed; extern crate lazy_static; use std::process; -use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::mpsc::channel; +use std::sync::Arc; use crossfire::mpsc::unbounded_future; @@ -138,7 +138,7 @@ fn main() { let (window_command_sender, window_command_receiver) = channel(); // We need to keep the bridge reference around to prevent the tokio runtime from getting freed - let bridge = start_bridge( + let _bridge = start_bridge( ui_command_sender.clone(), ui_command_receiver, redraw_event_sender, diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 26a3942..06cdca3 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -69,7 +69,7 @@ impl Settings { log_to_file = true; false } else { - !(arg.starts_with("--geometry=") || arg == "--wsl") + !(arg.starts_with("--geometry=") || arg == "--wsl" || arg == "--multiGrid") } }) .collect::>(); @@ -194,12 +194,30 @@ impl Settings { #[cfg(test)] mod tests { - use neovim_lib::{Neovim, NeovimApi, Session, UiAttachOptions}; + use async_trait::async_trait; + use nvim_rs::create::tokio as create; + use nvim_rs::{compat::tokio::Compat, Handler, Neovim}; + use tokio; use super::*; - use crate::bridge::create_nvim_command; + #[derive(Clone)] + pub struct NeovimHandler(); + + #[async_trait] + impl Handler for NeovimHandler { + type Writer = Compat; + + async fn handle_notify( + &self, + _event_name: String, + _arguments: Vec, + _neovim: Neovim>, + ) { + } + } + #[test] fn test_set_setting_handlers() { let settings = Settings::new(); @@ -271,8 +289,8 @@ mod tests { assert_eq!(v2, r2); } - #[test] - fn test_read_initial_values() { + #[tokio::test] + async fn test_read_initial_values() { let settings = Settings::new(); let v1: String = "foo".to_string(); @@ -281,12 +299,10 @@ mod tests { let v4: String = format!("neovide_{}", v1); let v5: String = format!("neovide_{}", v2); - let mut session = Session::new_child_cmd(&mut create_nvim_command()) - .unwrap_or_explained_panic("Could not locate or start neovim process"); - session.start_event_loop_channel(); - let mut nvim = Neovim::new(session); - - nvim.set_var(&v4, Value::from(v2.clone())).unwrap(); + let (nvim, _, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler()) + .await + .unwrap_or_explained_panic("Could not locate or start the neovim process"); + nvim.set_var(&v4, Value::from(v2.clone())).await.ok(); fn noop_update(_v: Value) {} @@ -310,10 +326,10 @@ mod tests { settings.readers.force_unlock_write(); } - settings.read_initial_values(&mut nvim); + settings.read_initial_values(&nvim).await; - let rt1 = nvim.get_var(&v4).unwrap(); - let rt2 = nvim.get_var(&v5).unwrap(); + let rt1 = nvim.get_var(&v4).await.unwrap(); + let rt2 = nvim.get_var(&v5).await.unwrap(); let r1 = rt1.as_str().unwrap(); let r2 = rt2.as_str().unwrap(); diff --git a/src/window/mod.rs b/src/window/mod.rs index 1df0c9d..d82ceef 100644 --- a/src/window/mod.rs +++ b/src/window/mod.rs @@ -3,7 +3,7 @@ mod settings; mod window_wrapper; use std::sync::atomic::AtomicBool; -use std::sync::mpsc::{Receiver, Sender}; +use std::sync::mpsc::Receiver; use std::sync::Arc; use crossfire::mpsc::TxUnbounded;