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"; | const BIN_PATH_ARG: &'static str = "--nvim-bin-path"; | ||||||
| 
 | 
 | ||||||
| fn main() { | 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); |     app.connect_activate(activate); | ||||||
| 
 | 
 | ||||||
|     let args: Vec<String> = env::args().collect(); |     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() { |     if open_arg().is_some() { | ||||||
|         argv.pop(); |         argv.pop(); | ||||||
|     } |     } | ||||||
| @ -42,14 +44,15 @@ fn activate(app: >k::Application) { | |||||||
| 
 | 
 | ||||||
|         let path = nvim_bin_path(std::env::args()); |         let path = nvim_bin_path(std::env::args()); | ||||||
|         let open_arg = open_arg(); |         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); |         guard_dispatch_thread(&mut *ui); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn nvim_bin_path<I>(args: I) -> Option<String> 
 | fn nvim_bin_path<I>(args: I) -> Option<String> | ||||||
|     where I: Iterator<Item=String> |     where I: Iterator<Item = String> | ||||||
| { | { | ||||||
|     args.skip_while(|a| !a.starts_with(BIN_PATH_ARG)) |     args.skip_while(|a| !a.starts_with(BIN_PATH_ARG)) | ||||||
|         .map(|p| p.split('=').nth(1).map(str::to_owned)) |         .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> { | 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> 
 | fn open_arg_impl<I>(args: I) -> Option<String> | ||||||
|     where I: Iterator<Item=String> |     where I: Iterator<Item = String> | ||||||
| { | { | ||||||
|     args.skip(1).last().map(|a| { |     args.skip(1) | ||||||
|         if !a.starts_with("-") { |         .last() | ||||||
|  |         .map(|a| if !a.starts_with("-") { | ||||||
|             Some(a.to_owned()) |             Some(a.to_owned()) | ||||||
|         } else { |         } else { | ||||||
|             None |             None | ||||||
|         } |         }) | ||||||
|     }).unwrap_or(None) |         .unwrap_or(None) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn guard_dispatch_thread(ui: &mut ui::Ui) { | fn guard_dispatch_thread(ui: &mut ui::Ui) { | ||||||
| @ -78,9 +82,7 @@ fn guard_dispatch_thread(ui: &mut ui::Ui) { | |||||||
|     thread::spawn(move || { |     thread::spawn(move || { | ||||||
|         guard.join().expect("Can't join dispatch thread"); |         guard.join().expect("Can't join dispatch thread"); | ||||||
|         glib::idle_add(move || { |         glib::idle_add(move || { | ||||||
|             ui::UI.with(|ui_cell| { |             ui::UI.with(|ui_cell| { ui_cell.borrow().destroy(); }); | ||||||
|                 ui_cell.borrow().destroy(); |  | ||||||
|             }); |  | ||||||
|             glib::Continue(false) |             glib::Continue(false) | ||||||
|         }); |         }); | ||||||
|     }); |     }); | ||||||
| @ -92,19 +94,25 @@ mod tests { | |||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_bin_path_arg() { |     fn test_bin_path_arg() { | ||||||
|         assert_eq!(Some("/test_path".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()))); |                    nvim_bin_path(vec!["neovim-gtk", "--nvim-bin-path=/test_path"] | ||||||
|  |                        .iter() | ||||||
|  |                        .map(|s| s.to_string()))); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_open_arg() { |     fn test_open_arg() { | ||||||
|         assert_eq!(Some("some_file.txt".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()))); |                    open_arg_impl(vec!["neovim-gtk", | ||||||
|  |                                       "--nvim-bin-path=/test_path", | ||||||
|  |                                       "some_file.txt"] | ||||||
|  |                        .iter() | ||||||
|  |                        .map(|s| s.to_string()))); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_empty_open_arg() { |     fn test_empty_open_arg() { | ||||||
|         assert_eq!(None, 
 |         assert_eq!(None, | ||||||
|                    open_arg_impl(vec!["neovim-gtk"].iter().map(|s| s.to_string()))); |                    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 { |     let session = if let Some(path) = nvim_bin_path { | ||||||
|         Session::new_child_path(path)? |         Session::new_child_path(path)? | ||||||
|     } else { |     } else { | ||||||
|  | |||||||
| @ -53,8 +53,9 @@ impl Settings { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if let Some(ref font_name) = self.gnome_interface_settings |         if let Some(ref font_name) = | ||||||
|                                          .get_string("monospace-font-name") { |             self.gnome_interface_settings | ||||||
|  |                 .get_string("monospace-font-name") { | ||||||
|             ui.set_font_desc(font_name); |             ui.set_font_desc(font_name); | ||||||
|             self.font_source = FontSource::Gnome; |             self.font_source = FontSource::Gnome; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -34,8 +34,8 @@ macro_rules! ui_thread_var { | |||||||
|     });) |     });) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ui_thread_var![UI, Ui, Ui::new()]; | ui_thread_var![UI, Ui, Ui::new()] | ||||||
| ui_thread_var![SET, settings::Settings, settings::Settings::new()]; | ui_thread_var![SET, settings::Settings, settings::Settings::new()] | ||||||
| 
 | 
 | ||||||
| #[derive(PartialEq)] | #[derive(PartialEq)] | ||||||
| enum NvimMode { | enum NvimMode { | ||||||
| @ -125,7 +125,7 @@ impl Ui { | |||||||
|         self.drawing_area |         self.drawing_area | ||||||
|             .set_events((gdk_sys::GDK_BUTTON_RELEASE_MASK | gdk_sys::GDK_BUTTON_PRESS_MASK | |             .set_events((gdk_sys::GDK_BUTTON_RELEASE_MASK | gdk_sys::GDK_BUTTON_PRESS_MASK | | ||||||
|                          gdk_sys::GDK_BUTTON_MOTION_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_press_event(gtk_button_press); | ||||||
|         self.drawing_area.connect_button_release_event(gtk_button_release); |         self.drawing_area.connect_button_release_event(gtk_button_release); | ||||||
|         self.drawing_area.connect_motion_notify_event(gtk_motion_notify); |         self.drawing_area.connect_motion_notify_event(gtk_motion_notify); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 daa
						daa