2016-03-16 14:39:53 +00:00
|
|
|
extern crate gtk;
|
2017-03-09 08:44:22 +00:00
|
|
|
extern crate gtk_sys;
|
2017-03-06 13:58:10 +00:00
|
|
|
extern crate gio;
|
2016-03-31 13:52:22 +00:00
|
|
|
extern crate gdk;
|
2016-05-05 07:23:04 +00:00
|
|
|
extern crate gdk_sys;
|
2016-03-28 14:14:10 +00:00
|
|
|
extern crate glib;
|
2016-03-16 14:39:53 +00:00
|
|
|
extern crate cairo;
|
2017-03-05 22:28:07 +00:00
|
|
|
extern crate pango;
|
|
|
|
extern crate pangocairo;
|
2016-03-19 10:27:39 +00:00
|
|
|
extern crate neovim_lib;
|
2016-04-02 20:00:18 +00:00
|
|
|
extern crate phf;
|
2017-04-12 10:12:05 +00:00
|
|
|
#[macro_use]
|
2017-04-03 11:17:06 +00:00
|
|
|
extern crate log;
|
|
|
|
extern crate env_logger;
|
2017-05-13 14:31:19 +00:00
|
|
|
extern crate htmlescape;
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
extern crate serde;
|
|
|
|
extern crate toml;
|
2016-03-16 14:39:53 +00:00
|
|
|
|
2017-07-08 11:02:56 +00:00
|
|
|
mod value;
|
2016-03-19 08:47:23 +00:00
|
|
|
mod ui_model;
|
2017-03-23 15:04:24 +00:00
|
|
|
#[macro_use]
|
2016-03-16 15:25:25 +00:00
|
|
|
mod ui;
|
2017-03-31 10:22:05 +00:00
|
|
|
mod nvim;
|
2017-03-23 15:04:24 +00:00
|
|
|
mod shell;
|
2016-04-04 10:14:57 +00:00
|
|
|
mod input;
|
2017-03-13 15:03:32 +00:00
|
|
|
mod settings;
|
2017-03-22 15:37:18 +00:00
|
|
|
mod cursor;
|
2017-04-01 10:00:14 +00:00
|
|
|
mod shell_dlg;
|
2017-04-19 08:40:53 +00:00
|
|
|
mod popup_menu;
|
2017-05-13 14:31:19 +00:00
|
|
|
mod project;
|
2017-05-27 16:50:25 +00:00
|
|
|
mod tabline;
|
2017-07-06 09:41:35 +00:00
|
|
|
mod error;
|
2016-03-16 14:39:53 +00:00
|
|
|
|
2017-03-06 13:58:10 +00:00
|
|
|
use std::env;
|
|
|
|
use gio::ApplicationExt;
|
2016-05-05 14:27:45 +00:00
|
|
|
|
2017-04-12 10:12:05 +00:00
|
|
|
use ui::Ui;
|
2017-03-16 10:18:13 +00:00
|
|
|
|
2017-06-04 10:14:09 +00:00
|
|
|
use shell::ShellOptions;
|
|
|
|
|
2017-03-07 15:20:48 +00:00
|
|
|
const BIN_PATH_ARG: &'static str = "--nvim-bin-path";
|
|
|
|
|
2016-03-16 15:25:25 +00:00
|
|
|
fn main() {
|
2017-04-03 11:17:06 +00:00
|
|
|
env_logger::init().expect("Can't initialize env_logger");
|
|
|
|
|
2017-05-13 21:30:34 +00:00
|
|
|
let app = if cfg!(debug_assertions) {
|
|
|
|
gtk::Application::new(Some("org.daa.NeovimGtkDebug"),
|
|
|
|
gio::ApplicationFlags::empty())
|
|
|
|
} else {
|
|
|
|
gtk::Application::new(Some("org.daa.NeovimGtk"), gio::ApplicationFlags::empty())
|
|
|
|
}
|
2017-03-14 19:31:56 +00:00
|
|
|
.expect("Failed to initialize GTK application");
|
2017-03-06 13:58:10 +00:00
|
|
|
|
|
|
|
app.connect_activate(activate);
|
|
|
|
|
|
|
|
let args: Vec<String> = env::args().collect();
|
2017-04-12 10:12:05 +00:00
|
|
|
let mut argv: Vec<&str> = args.iter()
|
|
|
|
.filter(|a| !a.starts_with(BIN_PATH_ARG))
|
|
|
|
.map(String::as_str)
|
|
|
|
.collect();
|
2017-03-14 09:37:06 +00:00
|
|
|
if open_arg().is_some() {
|
|
|
|
argv.pop();
|
|
|
|
}
|
2017-03-06 13:58:10 +00:00
|
|
|
app.run(argv.len() as i32, &argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn activate(app: >k::Application) {
|
2017-06-04 10:14:09 +00:00
|
|
|
let mut ui = Ui::new(ShellOptions::new(nvim_bin_path(std::env::args()), open_arg()));
|
2017-04-12 10:12:05 +00:00
|
|
|
|
2017-06-04 10:14:09 +00:00
|
|
|
ui.init(app);
|
2016-03-16 14:39:53 +00:00
|
|
|
}
|
|
|
|
|
2017-03-14 19:31:56 +00:00
|
|
|
fn nvim_bin_path<I>(args: I) -> Option<String>
|
|
|
|
where I: Iterator<Item = String>
|
2017-03-14 09:37:06 +00:00
|
|
|
{
|
|
|
|
args.skip_while(|a| !a.starts_with(BIN_PATH_ARG))
|
2017-03-07 15:20:48 +00:00
|
|
|
.map(|p| p.split('=').nth(1).map(str::to_owned))
|
|
|
|
.nth(0)
|
|
|
|
.unwrap_or(None)
|
|
|
|
}
|
|
|
|
|
2017-03-14 09:37:06 +00:00
|
|
|
fn open_arg() -> Option<String> {
|
2017-03-14 19:31:56 +00:00
|
|
|
open_arg_impl(std::env::args())
|
2017-03-14 09:37:06 +00:00
|
|
|
}
|
|
|
|
|
2017-03-14 19:31:56 +00:00
|
|
|
fn open_arg_impl<I>(args: I) -> Option<String>
|
|
|
|
where I: Iterator<Item = String>
|
2017-03-14 09:37:06 +00:00
|
|
|
{
|
2017-03-14 19:31:56 +00:00
|
|
|
args.skip(1)
|
|
|
|
.last()
|
|
|
|
.map(|a| if !a.starts_with("-") {
|
2017-04-12 10:12:05 +00:00
|
|
|
Some(a.to_owned())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
})
|
2017-03-14 19:31:56 +00:00
|
|
|
.unwrap_or(None)
|
2017-03-14 09:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_bin_path_arg() {
|
2017-03-14 19:31:56 +00:00
|
|
|
assert_eq!(Some("/test_path".to_string()),
|
|
|
|
nvim_bin_path(vec!["neovim-gtk", "--nvim-bin-path=/test_path"]
|
2017-04-12 10:12:05 +00:00
|
|
|
.iter()
|
|
|
|
.map(|s| s.to_string())));
|
2017-03-14 09:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_open_arg() {
|
2017-03-14 19:31:56 +00:00
|
|
|
assert_eq!(Some("some_file.txt".to_string()),
|
|
|
|
open_arg_impl(vec!["neovim-gtk",
|
|
|
|
"--nvim-bin-path=/test_path",
|
|
|
|
"some_file.txt"]
|
2017-04-12 10:12:05 +00:00
|
|
|
.iter()
|
|
|
|
.map(|s| s.to_string())));
|
2017-03-14 09:37:06 +00:00
|
|
|
}
|
2017-03-14 19:31:07 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_empty_open_arg() {
|
2017-03-14 19:31:56 +00:00
|
|
|
assert_eq!(None,
|
2017-03-14 19:31:07 +00:00
|
|
|
open_arg_impl(vec!["neovim-gtk"].iter().map(|s| s.to_string())));
|
|
|
|
}
|
2017-03-14 09:37:06 +00:00
|
|
|
}
|