Merge branch 'master' of ssh://daaparts.info/home/git/neovim-gtk
This commit is contained in:
commit
c83fc54270
38
Cargo.lock
generated
38
Cargo.lock
generated
@ -5,6 +5,8 @@ dependencies = [
|
|||||||
"cairo-rs 0.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"gtk 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"neovim-lib 0.1.0",
|
||||||
|
"rmp 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -24,6 +26,11 @@ name = "bitflags"
|
|||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "0.3.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "c_vec"
|
name = "c_vec"
|
||||||
version = "1.0.12"
|
version = "1.0.12"
|
||||||
@ -185,6 +192,15 @@ name = "libc"
|
|||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "neovim-lib"
|
||||||
|
version = "0.1.0"
|
||||||
|
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)",
|
||||||
|
"rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pango"
|
name = "pango"
|
||||||
version = "0.0.7"
|
version = "0.0.7"
|
||||||
@ -212,3 +228,25 @@ name = "pkg-config"
|
|||||||
version = "0.3.8"
|
version = "0.3.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rmp"
|
||||||
|
version = "0.7.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rmp-serialize"
|
||||||
|
version = "0.7.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)",
|
||||||
|
"rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-serialize"
|
||||||
|
version = "0.3.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ build = "build.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cairo-rs = "0.0.8"
|
cairo-rs = "0.0.8"
|
||||||
glib = "0.0.8"
|
glib = "0.0.8"
|
||||||
|
neovim-lib = "0.1"
|
||||||
|
rmp = "0.7"
|
||||||
|
|
||||||
[dependencies.gtk]
|
[dependencies.gtk]
|
||||||
version = "0.0.7"
|
version = "0.0.7"
|
||||||
|
2
build.rs
2
build.rs
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
if cfg!(target = "windows") {
|
||||||
println!("cargo:rustc-link-search=native=C:\\msys64\\mingw64\\lib");
|
println!("cargo:rustc-link-search=native=C:\\msys64\\mingw64\\lib");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
extern crate gtk;
|
extern crate gtk;
|
||||||
extern crate cairo;
|
extern crate cairo;
|
||||||
|
extern crate neovim_lib;
|
||||||
|
extern crate rmp;
|
||||||
|
|
||||||
|
mod nvim;
|
||||||
|
mod ui_model;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
use ui::Ui;
|
use ui::Ui;
|
||||||
|
use nvim::Nvim;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
Ui::new().start();
|
let nvim = Nvim::start().expect("Can't start nvim instance");
|
||||||
|
Ui::new().show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
45
src/nvim.rs
Normal file
45
src/nvim.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
use neovim_lib::{Neovim, NeovimApi, 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);
|
||||||
|
// 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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
src/ui.rs
12
src/ui.rs
@ -3,14 +3,20 @@ use gtk;
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{Window, WindowType, DrawingArea, Grid, ToolButton, ButtonBox, Orientation, Image};
|
use gtk::{Window, WindowType, DrawingArea, Grid, ToolButton, ButtonBox, Orientation, Image};
|
||||||
|
|
||||||
pub struct Ui;
|
use ui_model::UiModel;
|
||||||
|
|
||||||
|
pub struct Ui {
|
||||||
|
model: UiModel,
|
||||||
|
}
|
||||||
|
|
||||||
impl Ui {
|
impl Ui {
|
||||||
pub fn new() -> 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");
|
gtk::init().expect("Failed to initialize GTK");
|
||||||
let window = Window::new(WindowType::Toplevel);
|
let window = Window::new(WindowType::Toplevel);
|
||||||
|
|
||||||
|
44
src/ui_model.rs
Normal file
44
src/ui_model.rs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
pub struct Cell {
|
||||||
|
ch: char,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cell {
|
||||||
|
pub fn new(ch: char) -> Cell {
|
||||||
|
Cell { ch: ch }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct UiModel {
|
||||||
|
columns: u64,
|
||||||
|
rows: u64,
|
||||||
|
cur_row: u64,
|
||||||
|
cur_col: u64,
|
||||||
|
model: Vec<Cell>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
for i in 0..cells {
|
||||||
|
model[i] = Cell::new(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
UiModel {
|
||||||
|
columns: columns,
|
||||||
|
rows: rows,
|
||||||
|
cur_row: 0,
|
||||||
|
cur_col: 0,
|
||||||
|
model: model,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_cursor(&mut self, col: u64, row: u64) {
|
||||||
|
self.cur_col = col;
|
||||||
|
self.cur_row = row;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user