From efd982632445903cf7f4c90722746290766ad65f Mon Sep 17 00:00:00 2001 From: daa84 Date: Tue, 7 Mar 2017 18:20:48 +0300 Subject: [PATCH] Add --nvim-bin-path command line option --- README.md | 7 +++++++ src/main.rs | 15 +++++++++++++-- src/nvim.rs | 11 ++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bf14d63..33d9f3d 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,10 @@ To setup font add next line to *ginit.vim* ```vim call rpcnotify(1, 'Gui', 'Font', 'DejaVu Sans Mono 12') ``` + +# Command line +As this project uses gtk-rs, custom option by GtkApplication not supported yet. +There is workaround to pass nvim execution path. +```bat +cargo run -- --nvim-bin-path=E:\Neovim\bin\nvim.exe +``` diff --git a/src/main.rs b/src/main.rs index ebb0cd4..2eca285 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,13 +18,15 @@ use std::thread; use std::env; use gio::ApplicationExt; +const BIN_PATH_ARG: &'static str = "--nvim-bin-path"; + fn main() { let app = gtk::Application::new(Some("org.gtk.neovim-gtk"), gio::ApplicationFlags::empty()).expect("Failed to initialize GTK application"); app.connect_activate(activate); let args: Vec = env::args().collect(); - let argv: Vec<&str> = args.iter().map(String::as_str).collect(); + let argv: Vec<&str> = args.iter().filter(|a| !a.starts_with(BIN_PATH_ARG)).map(String::as_str).collect(); app.run(argv.len() as i32, &argv); } @@ -33,12 +35,21 @@ fn activate(app: >k::Application) { let mut ui = ui_cell.borrow_mut(); ui.init(app); - nvim::initialize(&mut *ui).expect("Can't start nvim instance"); + let path = nvim_bin_path(); + nvim::initialize(&mut *ui, path.as_ref()).expect("Can't start nvim instance"); guard_dispatch_thread(&mut *ui); }); } +fn nvim_bin_path() -> Option { + std::env::args() + .skip_while(|a| !a.starts_with(BIN_PATH_ARG)) + .map(|p| p.split('=').nth(1).map(str::to_owned)) + .nth(0) + .unwrap_or(None) +} + fn guard_dispatch_thread(ui: &mut ui::Ui) { let guard = ui.nvim().session.take_dispatch_guard(); thread::spawn(move || { diff --git a/src/nvim.rs b/src/nvim.rs index 6740864..3a1627f 100644 --- a/src/nvim.rs +++ b/src/nvim.rs @@ -63,13 +63,14 @@ macro_rules! try_uint { }) } -pub fn initialize(ui: &mut Ui) -> Result<()> { - // let mut session = try!(Session::new_tcp("127.0.0.1:6666")); - let session = if cfg!(target_os = "windows") { - Session::new_child_path("E:\\Neovim\\bin\\nvim.exe").unwrap() +pub fn initialize(ui: &mut Ui, nvim_bin_path: Option<&String>) -> Result<()> { + let session = if let Some(path) = nvim_bin_path { + println!("{}", path); + Session::new_child_path(path)? } else { - Session::new_child().unwrap() + Session::new_child()? }; + let nvim = Neovim::new(session); ui.set_nvim(nvim); ui.model = UiModel::new(24, 80);