Add --nvim-bin-path command line option
This commit is contained in:
parent
bde70d7797
commit
efd9826324
@ -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
|
||||
```
|
||||
|
15
src/main.rs
15
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<String> = 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<String> {
|
||||
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 || {
|
||||
|
11
src/nvim.rs
11
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);
|
||||
|
Loading…
Reference in New Issue
Block a user