diff --git a/src/main.rs b/src/main.rs index 5f0273f..895518e 100644 --- a/src/main.rs +++ b/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 = 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(args: I) -> Option - where I: Iterator +fn nvim_bin_path(args: I) -> Option + where I: Iterator { 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(args: I) -> Option } fn open_arg() -> Option { - open_arg_impl(std::env::args()) + open_arg_impl(std::env::args()) } -fn open_arg_impl(args: I) -> Option - where I: Iterator +fn open_arg_impl(args: I) -> Option + where I: Iterator { - 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()))); } } diff --git a/src/nvim.rs b/src/nvim.rs index bb4e7b6..041cd2b 100644 --- a/src/nvim.rs +++ b/src/nvim.rs @@ -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 { diff --git a/src/settings.rs b/src/settings.rs index 780e5cf..6ba7297 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -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; } diff --git a/src/ui.rs b/src/ui.rs index 1f63cc0..fc2064e 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -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);