Fixes #1 Temproray fix that allows open single file
To make good fix wait for gtk-rs bindings udpate for optons/open support inside GtkApplication
This commit is contained in:
parent
b68d2470c3
commit
fde94bd64a
50
src/main.rs
50
src/main.rs
@ -28,7 +28,10 @@ fn main() {
|
|||||||
app.connect_activate(activate);
|
app.connect_activate(activate);
|
||||||
|
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let argv: Vec<&str> = args.iter().filter(|a| !a.starts_with(BIN_PATH_ARG)).map(String::as_str).collect();
|
let mut argv: Vec<&str> = args.iter().filter(|a| !a.starts_with(BIN_PATH_ARG)).map(String::as_str).collect();
|
||||||
|
if open_arg().is_some() {
|
||||||
|
argv.pop();
|
||||||
|
}
|
||||||
app.run(argv.len() as i32, &argv);
|
app.run(argv.len() as i32, &argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,21 +40,39 @@ fn activate(app: >k::Application) {
|
|||||||
let mut ui = ui_cell.borrow_mut();
|
let mut ui = ui_cell.borrow_mut();
|
||||||
ui.init(app);
|
ui.init(app);
|
||||||
|
|
||||||
let path = nvim_bin_path();
|
let path = nvim_bin_path(std::env::args());
|
||||||
nvim::initialize(&mut *ui, path.as_ref()).expect("Can't start nvim instance");
|
let open_arg = open_arg();
|
||||||
|
nvim::initialize(&mut *ui, path.as_ref(), open_arg.as_ref()).expect("Can't start nvim instance");
|
||||||
|
|
||||||
guard_dispatch_thread(&mut *ui);
|
guard_dispatch_thread(&mut *ui);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nvim_bin_path() -> Option<String> {
|
fn nvim_bin_path<I>(args: I) -> Option<String>
|
||||||
std::env::args()
|
where I: Iterator<Item=String>
|
||||||
.skip_while(|a| !a.starts_with(BIN_PATH_ARG))
|
{
|
||||||
|
args.skip_while(|a| !a.starts_with(BIN_PATH_ARG))
|
||||||
.map(|p| p.split('=').nth(1).map(str::to_owned))
|
.map(|p| p.split('=').nth(1).map(str::to_owned))
|
||||||
.nth(0)
|
.nth(0)
|
||||||
.unwrap_or(None)
|
.unwrap_or(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn open_arg() -> Option<String> {
|
||||||
|
open_arg_impl(std::env::args())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn open_arg_impl<I>(args: I) -> Option<String>
|
||||||
|
where I: Iterator<Item=String>
|
||||||
|
{
|
||||||
|
args.last().map(|a| {
|
||||||
|
if !a.starts_with("-") {
|
||||||
|
Some(a.to_owned())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}).unwrap_or(None)
|
||||||
|
}
|
||||||
|
|
||||||
fn guard_dispatch_thread(ui: &mut ui::Ui) {
|
fn guard_dispatch_thread(ui: &mut ui::Ui) {
|
||||||
let guard = ui.nvim().session.take_dispatch_guard();
|
let guard = ui.nvim().session.take_dispatch_guard();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
@ -64,3 +85,20 @@ fn guard_dispatch_thread(ui: &mut ui::Ui) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bin_path_arg() {
|
||||||
|
assert_eq!(Some("/test_path".to_string()),
|
||||||
|
nvim_bin_path(vec!["neovim-gtk", "--nvim-bin-path=/test_path"].iter().map(|s| s.to_string())));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_open_arg() {
|
||||||
|
assert_eq!(Some("some_file.txt".to_string()),
|
||||||
|
open_arg_impl(vec!["neovim-gtk", "--nvim-bin-path=/test_path", "some_file.txt"].iter().map(|s| s.to_string())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -64,7 +64,7 @@ macro_rules! try_uint {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initialize(ui: &mut Ui, nvim_bin_path: Option<&String>) -> Result<()> {
|
pub fn initialize(ui: &mut Ui, nvim_bin_path: Option<&String>, open_arg: Option<&String>) -> Result<()> {
|
||||||
let session = if let Some(path) = nvim_bin_path {
|
let session = if let Some(path) = nvim_bin_path {
|
||||||
Session::new_child_path(path)?
|
Session::new_child_path(path)?
|
||||||
} else {
|
} else {
|
||||||
@ -81,6 +81,10 @@ pub fn initialize(ui: &mut Ui, nvim_bin_path: Option<&String>) -> Result<()> {
|
|||||||
nvim.ui_attach(80, 24, UiAttachOptions::new()).map_err(|e| Error::new(ErrorKind::Other, e))?;
|
nvim.ui_attach(80, 24, UiAttachOptions::new()).map_err(|e| Error::new(ErrorKind::Other, e))?;
|
||||||
nvim.command("runtime! ginit.vim").map_err(|e| Error::new(ErrorKind::Other, e))?;
|
nvim.command("runtime! ginit.vim").map_err(|e| Error::new(ErrorKind::Other, e))?;
|
||||||
|
|
||||||
|
if let Some(ref file) = open_arg {
|
||||||
|
nvim.command(&format!("e {}", file)).report_err(nvim);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user