Nvim connection with events handler
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
extern crate gtk;
|
||||
extern crate cairo;
|
||||
extern crate neovim_lib;
|
||||
extern crate rmp;
|
||||
|
||||
mod nvim;
|
||||
mod ui_model;
|
||||
mod ui;
|
||||
|
||||
use ui::Ui;
|
||||
use nvim::Nvim;
|
||||
|
||||
fn main() {
|
||||
Ui::new().start();
|
||||
let nvim = Nvim::start().expect("Can't start nvim instance");
|
||||
Ui::new().show();
|
||||
}
|
||||
|
||||
|
||||
43
src/nvim.rs
Normal file
43
src/nvim.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use neovim_lib::{Neovim, Session};
|
||||
use std::io::{Result, Error, ErrorKind};
|
||||
use rmp::Value;
|
||||
|
||||
pub struct Nvim {
|
||||
nvim: Neovim
|
||||
}
|
||||
|
||||
impl Nvim {
|
||||
pub fn start() -> 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);
|
||||
|
||||
let mut nvim = Neovim::new(session);
|
||||
try!(nvim.ui_attach(80, 24, true).map_err(|e| Error::new(ErrorKind::Other, e)));
|
||||
|
||||
Ok(Nvim {
|
||||
nvim: nvim,
|
||||
})
|
||||
}
|
||||
|
||||
fn cb(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 {
|
||||
println!("Unsupported event {:?}", ev_args);
|
||||
}
|
||||
}
|
||||
else {
|
||||
println!("Unsupported event type {:?}", ev);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("Notification {}", method);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/ui.rs
10
src/ui.rs
@@ -5,14 +5,18 @@ use gtk::{Window, WindowType, DrawingArea, Grid, Button, ButtonBox, Orientation}
|
||||
|
||||
use ui_model::UiModel;
|
||||
|
||||
pub struct Ui;
|
||||
pub struct Ui {
|
||||
model: UiModel,
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
pub fn new() -> Ui {
|
||||
Ui
|
||||
Ui {
|
||||
model: UiModel::empty(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start(&self) {
|
||||
pub fn show(&self) {
|
||||
gtk::init().expect("Failed to initialize GTK");
|
||||
let window = Window::new(WindowType::Toplevel);
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@ pub struct UiModel {
|
||||
}
|
||||
|
||||
impl UiModel {
|
||||
pub fn empty() -> UiModel {
|
||||
UiModel::new(0, 0)
|
||||
}
|
||||
|
||||
pub fn new(columns: u64, rows: u64) -> UiModel {
|
||||
let cells = (columns * rows) as usize;
|
||||
let mut model = Vec::with_capacity(cells);
|
||||
|
||||
Reference in New Issue
Block a user