Rustfmt
This commit is contained in:
parent
b7aff3e7ac
commit
b910c9ba6a
48
src/main.rs
48
src/main.rs
@ -23,12 +23,14 @@ use gio::ApplicationExt;
|
||||
const BIN_PATH_ARG: &'static str = "--nvim-bin-path";
|
||||
|
||||
fn main() {
|
||||
let app = gtk::Application::new(Some("org.gtk.neovim-gtk"), gio::ApplicationFlags::empty()).expect("Failed to initialize GTK application");
|
||||
let app = gtk::Application::new(Some("org.gtk.neovim-gtk"), gio::ApplicationFlags::empty())
|
||||
.expect("Failed to initialize GTK application");
|
||||
|
||||
app.connect_activate(activate);
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let mut argv: Vec<&str> = args.iter().filter(|a| !a.starts_with(BIN_PATH_ARG)).map(String::as_str).collect();
|
||||
let mut argv: Vec<&str> =
|
||||
args.iter().filter(|a| !a.starts_with(BIN_PATH_ARG)).map(String::as_str).collect();
|
||||
if open_arg().is_some() {
|
||||
argv.pop();
|
||||
}
|
||||
@ -42,14 +44,15 @@ fn activate(app: >k::Application) {
|
||||
|
||||
let path = nvim_bin_path(std::env::args());
|
||||
let open_arg = open_arg();
|
||||
nvim::initialize(&mut *ui, path.as_ref(), open_arg.as_ref()).expect("Can't start nvim instance");
|
||||
nvim::initialize(&mut *ui, path.as_ref(), open_arg.as_ref())
|
||||
.expect("Can't start nvim instance");
|
||||
|
||||
guard_dispatch_thread(&mut *ui);
|
||||
});
|
||||
}
|
||||
|
||||
fn nvim_bin_path<I>(args: I) -> Option<String>
|
||||
where I: Iterator<Item=String>
|
||||
fn nvim_bin_path<I>(args: I) -> Option<String>
|
||||
where I: Iterator<Item = String>
|
||||
{
|
||||
args.skip_while(|a| !a.starts_with(BIN_PATH_ARG))
|
||||
.map(|p| p.split('=').nth(1).map(str::to_owned))
|
||||
@ -58,19 +61,20 @@ fn nvim_bin_path<I>(args: I) -> Option<String>
|
||||
}
|
||||
|
||||
fn open_arg() -> Option<String> {
|
||||
open_arg_impl(std::env::args())
|
||||
open_arg_impl(std::env::args())
|
||||
}
|
||||
|
||||
fn open_arg_impl<I>(args: I) -> Option<String>
|
||||
where I: Iterator<Item=String>
|
||||
fn open_arg_impl<I>(args: I) -> Option<String>
|
||||
where I: Iterator<Item = String>
|
||||
{
|
||||
args.skip(1).last().map(|a| {
|
||||
if !a.starts_with("-") {
|
||||
args.skip(1)
|
||||
.last()
|
||||
.map(|a| if !a.starts_with("-") {
|
||||
Some(a.to_owned())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).unwrap_or(None)
|
||||
})
|
||||
.unwrap_or(None)
|
||||
}
|
||||
|
||||
fn guard_dispatch_thread(ui: &mut ui::Ui) {
|
||||
@ -78,9 +82,7 @@ fn guard_dispatch_thread(ui: &mut ui::Ui) {
|
||||
thread::spawn(move || {
|
||||
guard.join().expect("Can't join dispatch thread");
|
||||
glib::idle_add(move || {
|
||||
ui::UI.with(|ui_cell| {
|
||||
ui_cell.borrow().destroy();
|
||||
});
|
||||
ui::UI.with(|ui_cell| { ui_cell.borrow().destroy(); });
|
||||
glib::Continue(false)
|
||||
});
|
||||
});
|
||||
@ -92,19 +94,25 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_bin_path_arg() {
|
||||
assert_eq!(Some("/test_path".to_string()),
|
||||
nvim_bin_path(vec!["neovim-gtk", "--nvim-bin-path=/test_path"].iter().map(|s| s.to_string())));
|
||||
assert_eq!(Some("/test_path".to_string()),
|
||||
nvim_bin_path(vec!["neovim-gtk", "--nvim-bin-path=/test_path"]
|
||||
.iter()
|
||||
.map(|s| s.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_open_arg() {
|
||||
assert_eq!(Some("some_file.txt".to_string()),
|
||||
open_arg_impl(vec!["neovim-gtk", "--nvim-bin-path=/test_path", "some_file.txt"].iter().map(|s| s.to_string())));
|
||||
assert_eq!(Some("some_file.txt".to_string()),
|
||||
open_arg_impl(vec!["neovim-gtk",
|
||||
"--nvim-bin-path=/test_path",
|
||||
"some_file.txt"]
|
||||
.iter()
|
||||
.map(|s| s.to_string())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_open_arg() {
|
||||
assert_eq!(None,
|
||||
assert_eq!(None,
|
||||
open_arg_impl(vec!["neovim-gtk"].iter().map(|s| s.to_string())));
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,10 @@ macro_rules! try_uint {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn initialize(ui: &mut Ui, nvim_bin_path: Option<&String>, open_arg: Option<&String>) -> Result<()> {
|
||||
pub fn initialize(ui: &mut Ui,
|
||||
nvim_bin_path: Option<&String>,
|
||||
open_arg: Option<&String>)
|
||||
-> Result<()> {
|
||||
let session = if let Some(path) = nvim_bin_path {
|
||||
Session::new_child_path(path)?
|
||||
} else {
|
||||
|
@ -53,8 +53,9 @@ impl Settings {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(ref font_name) = self.gnome_interface_settings
|
||||
.get_string("monospace-font-name") {
|
||||
if let Some(ref font_name) =
|
||||
self.gnome_interface_settings
|
||||
.get_string("monospace-font-name") {
|
||||
ui.set_font_desc(font_name);
|
||||
self.font_source = FontSource::Gnome;
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ macro_rules! ui_thread_var {
|
||||
});)
|
||||
}
|
||||
|
||||
ui_thread_var![UI, Ui, Ui::new()];
|
||||
ui_thread_var![SET, settings::Settings, settings::Settings::new()];
|
||||
ui_thread_var![UI, Ui, Ui::new()]
|
||||
ui_thread_var![SET, settings::Settings, settings::Settings::new()]
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum NvimMode {
|
||||
@ -125,7 +125,7 @@ impl Ui {
|
||||
self.drawing_area
|
||||
.set_events((gdk_sys::GDK_BUTTON_RELEASE_MASK | gdk_sys::GDK_BUTTON_PRESS_MASK |
|
||||
gdk_sys::GDK_BUTTON_MOTION_MASK)
|
||||
.bits() as i32);
|
||||
.bits() as i32);
|
||||
self.drawing_area.connect_button_press_event(gtk_button_press);
|
||||
self.drawing_area.connect_button_release_event(gtk_button_release);
|
||||
self.drawing_area.connect_motion_notify_event(gtk_motion_notify);
|
||||
|
Loading…
Reference in New Issue
Block a user