Move option set from args to ginit.vim
This commit is contained in:
parent
f32ddbd69c
commit
68963ab628
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -13,7 +13,7 @@ dependencies = [
|
||||
"gtk-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"neovim-lib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"neovim-lib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pango 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pangocairo 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -293,7 +293,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "neovim-lib"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -584,7 +584,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5"
|
||||
"checksum log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5141eca02775a762cc6cd564d8d2c50f67c0ea3a372cbf1c51592b3e029e10ad"
|
||||
"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
|
||||
"checksum neovim-lib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aa0477861ec64754cbc089f8a65db8092dc53c68e397315bf342d7781140be1b"
|
||||
"checksum neovim-lib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c4f4cf765a2dee99de95861fc1eea0b64da31552b2f8d85bfd1edb59fc26f1b9"
|
||||
"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99"
|
||||
"checksum pango 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4215233226ff03c9a3ed7c85cbc3c58257203723e3a93d5a20ce3560f66261b7"
|
||||
"checksum pango-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e401ee469540e60a80d1df63dcea4e9c201115e79344b77529fa3705ea8eadcd"
|
||||
|
20
src/main.rs
20
src/main.rs
@ -37,7 +37,6 @@ use gio::ApplicationExt;
|
||||
use ui::Ui;
|
||||
|
||||
const BIN_PATH_ARG: &'static str = "--nvim-bin-path";
|
||||
const ENABLE_EXTERNAL_POPUP: &'static str = "--enable-external-popup";
|
||||
|
||||
fn main() {
|
||||
env_logger::init().expect("Can't initialize env_logger");
|
||||
@ -55,7 +54,6 @@ fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let mut argv: Vec<&str> = args.iter()
|
||||
.filter(|a| !a.starts_with(BIN_PATH_ARG))
|
||||
.filter(|a| !a.starts_with(ENABLE_EXTERNAL_POPUP))
|
||||
.map(String::as_str)
|
||||
.collect();
|
||||
if open_arg().is_some() {
|
||||
@ -69,7 +67,6 @@ fn activate(app: >k::Application) {
|
||||
|
||||
ui.init(app,
|
||||
nvim_bin_path(std::env::args()).as_ref(),
|
||||
external_popup(std::env::args()),
|
||||
open_arg().as_ref());
|
||||
}
|
||||
|
||||
@ -82,15 +79,6 @@ fn nvim_bin_path<I>(args: I) -> Option<String>
|
||||
.unwrap_or(None)
|
||||
}
|
||||
|
||||
fn external_popup<I>(args: I) -> bool
|
||||
where I: Iterator<Item = String>
|
||||
{
|
||||
args.filter(|a| a.starts_with(ENABLE_EXTERNAL_POPUP))
|
||||
.map(|_| true)
|
||||
.nth(0)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn open_arg() -> Option<String> {
|
||||
open_arg_impl(std::env::args())
|
||||
}
|
||||
@ -112,14 +100,6 @@ fn open_arg_impl<I>(args: I) -> Option<String>
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_external_menu() {
|
||||
assert_eq!(true,
|
||||
external_popup(vec!["neovim-gtk", "--enable-external-popup"]
|
||||
.iter()
|
||||
.map(|s| s.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bin_path_arg() {
|
||||
assert_eq!(Some("/test_path".to_string()),
|
||||
|
20
src/nvim.rs
20
src/nvim.rs
@ -5,7 +5,7 @@ use std::result;
|
||||
use std::sync::Arc;
|
||||
|
||||
use ui::UiMutex;
|
||||
use neovim_lib::{Handler, Neovim, NeovimApi, Session, Value, UiAttachOptions, CallError};
|
||||
use neovim_lib::{Handler, Neovim, NeovimApi, Session, Value, UiAttachOptions, CallError, UiOption};
|
||||
use ui_model::{ModelRect, ModelRectVec};
|
||||
use shell;
|
||||
use glib;
|
||||
@ -70,8 +70,7 @@ macro_rules! try_uint {
|
||||
}
|
||||
|
||||
pub fn initialize(shell: Arc<UiMutex<shell::State>>,
|
||||
nvim_bin_path: Option<&String>,
|
||||
external_popup: bool)
|
||||
nvim_bin_path: Option<&String>)
|
||||
-> Result<Neovim> {
|
||||
let mut cmd = if let Some(path) = nvim_bin_path {
|
||||
Command::new(path)
|
||||
@ -90,8 +89,7 @@ pub fn initialize(shell: Arc<UiMutex<shell::State>>,
|
||||
if let Ok(runtime_path) = env::var("NVIM_GTK_RUNTIME_PATH") {
|
||||
cmd.arg("--cmd")
|
||||
.arg(format!("let &rtp.=',{}'", runtime_path));
|
||||
}
|
||||
else if let Some(prefix) = option_env!("PREFIX") {
|
||||
} else if let Some(prefix) = option_env!("PREFIX") {
|
||||
cmd.arg("--cmd")
|
||||
.arg(format!("let &rtp.=',{}/share/nvim-gtk/runtime'", prefix));
|
||||
} else {
|
||||
@ -113,7 +111,7 @@ pub fn initialize(shell: Arc<UiMutex<shell::State>>,
|
||||
nvim.session
|
||||
.start_event_loop_handler(NvimHandler::new(shell));
|
||||
let mut opts = UiAttachOptions::new();
|
||||
opts.set_popupmenu_external(external_popup);
|
||||
opts.set_popupmenu_external(false);
|
||||
nvim.ui_attach(80, 24, opts)
|
||||
.map_err(|e| Error::new(ErrorKind::Other, e))?;
|
||||
nvim.command("runtime! ginit.vim")
|
||||
@ -208,6 +206,16 @@ fn call_gui_event(ui: &mut shell::State,
|
||||
-> result::Result<(), String> {
|
||||
match method {
|
||||
"Font" => ui.set_font(try_str!(args[0])),
|
||||
"Option" => {
|
||||
match try_str!(args[0]) {
|
||||
"Popupmenu" => {
|
||||
ui.nvim()
|
||||
.set_option(UiOption::ExtPopupmenu(try_uint!(args[1]) == 1))
|
||||
.map_err(|e| e.to_string())?
|
||||
}
|
||||
opt => error!("Unknown option {}", opt),
|
||||
}
|
||||
}
|
||||
_ => return Err(format!("Unsupported event {}({:?})", method, args)),
|
||||
}
|
||||
Ok(())
|
||||
|
@ -313,9 +313,9 @@ impl Shell {
|
||||
state.cursor.as_mut().unwrap().start();
|
||||
}
|
||||
|
||||
pub fn init_nvim(&mut self, nvim_bin_path: Option<&String>, external_popup: bool) {
|
||||
pub fn init_nvim(&mut self, nvim_bin_path: Option<&String>) {
|
||||
let nvim =
|
||||
nvim::initialize(self.state.clone(), nvim_bin_path, external_popup).expect("Can't start nvim instance");
|
||||
nvim::initialize(self.state.clone(), nvim_bin_path).expect("Can't start nvim instance");
|
||||
let mut state = self.state.borrow_mut();
|
||||
state.nvim = Some(Rc::new(RefCell::new(nvim)));
|
||||
}
|
||||
|
@ -71,7 +71,6 @@ impl Ui {
|
||||
pub fn init(&mut self,
|
||||
app: >k::Application,
|
||||
nvim_bin_path: Option<&String>,
|
||||
external_popup: bool,
|
||||
open_path: Option<&String>) {
|
||||
if self.initialized {
|
||||
return;
|
||||
@ -125,7 +124,7 @@ impl Ui {
|
||||
window.connect_delete_event(move |_, _| gtk_delete(&*comps_ref, &*shell_ref));
|
||||
|
||||
shell.add_configure_event();
|
||||
shell.init_nvim(nvim_bin_path, external_popup);
|
||||
shell.init_nvim(nvim_bin_path);
|
||||
|
||||
if open_path.is_some() {
|
||||
shell.open_file(open_path.unwrap());
|
||||
|
Loading…
Reference in New Issue
Block a user