neovim-gtk/src/nvim.rs

50 lines
1.5 KiB
Rust
Raw Normal View History

2016-03-19 11:32:59 +00:00
use neovim_lib::{Neovim, NeovimApi, Session};
2016-03-19 10:27:39 +00:00
use std::io::{Result, Error, ErrorKind};
2016-03-25 09:51:28 +00:00
use std::sync::Arc;
2016-03-19 10:27:39 +00:00
use rmp::Value;
use ui::Ui;
2016-03-19 10:27:39 +00:00
pub struct Nvim {
2016-03-23 11:59:18 +00:00
nvim: Neovim,
}
pub trait RedrawEvents {
2016-03-19 10:27:39 +00:00
}
impl Nvim {
pub fn start(mut ui: Ui) -> Result<Nvim> {
2016-03-23 11:59:18 +00:00
// let mut session = try!(Session::new_tcp("127.0.0.1:6666"));
let session = if cfg!(target_os = "windows") {
2016-03-24 09:21:27 +00:00
Session::new_child_path("E:\\Neovim\\bin\\nvim.exe").unwrap()
} else {
Session::new_child().unwrap()
};
2016-03-19 10:27:39 +00:00
let mut nvim = Neovim::new(session);
nvim.session.start_event_loop_cb(move |m, p| Nvim::cb(&mut ui, m, p));
2016-03-19 11:32:59 +00:00
// fix neovim --embed bug to start embed mode
nvim.input("i").unwrap();
2016-03-19 10:27:39 +00:00
try!(nvim.ui_attach(80, 24, true).map_err(|e| Error::new(ErrorKind::Other, e)));
2016-03-23 11:59:18 +00:00
Ok(Nvim { nvim: nvim })
2016-03-19 10:27:39 +00:00
}
fn cb(ui: &mut Ui, method: &str, params: Vec<Value>) {
2016-03-19 10:27:39 +00:00
if method == "redraw" {
for ev in params {
if let Value::Array(ev_args) = ev {
if let Value::String(ref ev_name) = ev_args[0] {
println!("Event {}", ev_name);
2016-03-23 11:59:18 +00:00
} else {
2016-03-19 10:27:39 +00:00
println!("Unsupported event {:?}", ev_args);
}
2016-03-23 11:59:18 +00:00
} else {
2016-03-19 10:27:39 +00:00
println!("Unsupported event type {:?}", ev);
}
}
} else {
println!("Notification {}", method);
}
}
}