Add events callback
This commit is contained in:
parent
dc1bf55a46
commit
3fc2c3322d
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -5,7 +5,7 @@ dependencies = [
|
||||
"cairo-rs 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glib 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gtk 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"neovim-lib 0.1.0",
|
||||
"neovim-lib 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rmp 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -195,6 +195,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
[[package]]
|
||||
name = "neovim-lib"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"rmp 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rmp-serialize 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -11,7 +11,8 @@ use ui::Ui;
|
||||
use nvim::Nvim;
|
||||
|
||||
fn main() {
|
||||
let nvim = Nvim::start().expect("Can't start nvim instance");
|
||||
Ui::new().show();
|
||||
let ui = Ui::new();
|
||||
let nvim = Nvim::start(ui).expect("Can't start nvim instance");
|
||||
ui.show();
|
||||
}
|
||||
|
||||
|
23
src/nvim.rs
23
src/nvim.rs
@ -3,38 +3,37 @@ use std::io::{Result, Error, ErrorKind};
|
||||
use rmp::Value;
|
||||
|
||||
pub struct Nvim {
|
||||
nvim: Neovim
|
||||
nvim: Neovim,
|
||||
}
|
||||
|
||||
pub trait RedrawEvents {
|
||||
}
|
||||
|
||||
impl Nvim {
|
||||
pub fn start() -> Result<Nvim> {
|
||||
//let mut session = try!(Session::new_tcp("127.0.0.1:6666"));
|
||||
pub fn start<F: RedrawEvents + Send + 'static> (redraw_cb: F) -> Result<Nvim> {
|
||||
// let mut session = try!(Session::new_tcp("127.0.0.1:6666"));
|
||||
let mut session = try!(Session::new_child());
|
||||
|
||||
session.start_event_loop_cb(Nvim::cb);
|
||||
session.start_event_loop_cb(move |m, p| Nvim::cb(&redraw_cb, m, p));
|
||||
|
||||
let mut nvim = Neovim::new(session);
|
||||
// fix neovim --embed bug to start embed mode
|
||||
nvim.input("i").unwrap();
|
||||
try!(nvim.ui_attach(80, 24, true).map_err(|e| Error::new(ErrorKind::Other, e)));
|
||||
|
||||
Ok(Nvim {
|
||||
nvim: nvim,
|
||||
})
|
||||
Ok(Nvim { nvim: nvim })
|
||||
}
|
||||
|
||||
fn cb(method: &str, params: Vec<Value>) {
|
||||
fn cb<F: RedrawEvents>(readraw_cb: &F, method: &str, params: Vec<Value>) {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
println!("Unsupported event {:?}", ev_args);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
println!("Unsupported event type {:?}", ev);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user