From edaa867103ad168ec1b7148b3f4d796f33e0323a Mon Sep 17 00:00:00 2001 From: daa84 Date: Wed, 23 Mar 2016 18:22:28 +0300 Subject: [PATCH] some small step to implement events listener --- src/main.rs | 5 ++++- src/nvim.rs | 10 +++++----- src/ui.rs | 1 - 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9013f45..7f420c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); } diff --git a/src/nvim.rs b/src/nvim.rs index d2f7018..0af5d1a 100644 --- a/src/nvim.rs +++ b/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 (redraw_cb: F) -> Result { + pub fn start(mut ui: Ui) -> Result { // 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(readraw_cb: &F, method: &str, params: Vec) { + fn cb(ui: &mut Ui, method: &str, params: Vec) { if method == "redraw" { for ev in params { if let Value::Array(ev_args) = ev { diff --git a/src/ui.rs b/src/ui.rs index 12b996c..c05f6d7 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -53,7 +53,6 @@ impl Ui { Inhibit(false) }); - gtk::main(); } fn gtk_draw(drawing_area: &DrawingArea, ctx: &cairo::Context) -> Inhibit {