some small step to implement events listener
This commit is contained in:
parent
b5265c41f6
commit
edaa867103
@ -12,7 +12,10 @@ use nvim::Nvim;
|
||||
|
||||
fn main() {
|
||||
let ui = Ui::new();
|
||||
let nvim = Nvim::start(ui).expect("Can't start nvim instance");
|
||||
ui.show();
|
||||
|
||||
Nvim::start(ui).expect("Can't start nvim instance");
|
||||
|
||||
gtk::main();
|
||||
}
|
||||
|
||||
|
10
src/nvim.rs
10
src/nvim.rs
@ -1,6 +1,7 @@
|
||||
use neovim_lib::{Neovim, NeovimApi, Session};
|
||||
use std::io::{Result, Error, ErrorKind};
|
||||
use rmp::Value;
|
||||
use ui::Ui;
|
||||
|
||||
pub struct Nvim {
|
||||
nvim: Neovim,
|
||||
@ -10,13 +11,12 @@ pub trait RedrawEvents {
|
||||
}
|
||||
|
||||
impl Nvim {
|
||||
pub fn start<F: RedrawEvents + Send + 'static> (redraw_cb: F) -> Result<Nvim> {
|
||||
pub fn start(mut ui: Ui) -> 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(move |m, p| Nvim::cb(&redraw_cb, m, p));
|
||||
|
||||
let mut nvim = Neovim::new(session);
|
||||
|
||||
nvim.session.start_event_loop_cb(move |m, p| Nvim::cb(&mut ui, m, p));
|
||||
// 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)));
|
||||
@ -24,7 +24,7 @@ impl Nvim {
|
||||
Ok(Nvim { nvim: nvim })
|
||||
}
|
||||
|
||||
fn cb<F: RedrawEvents>(readraw_cb: &F, method: &str, params: Vec<Value>) {
|
||||
fn cb(ui: &mut Ui, method: &str, params: Vec<Value>) {
|
||||
if method == "redraw" {
|
||||
for ev in params {
|
||||
if let Value::Array(ev_args) = ev {
|
||||
|
Loading…
Reference in New Issue
Block a user