diff --git a/src/bridge/ui_commands.rs b/src/bridge/ui_commands.rs index 06c14a5..82e02ab 100644 --- a/src/bridge/ui_commands.rs +++ b/src/bridge/ui_commands.rs @@ -4,7 +4,7 @@ use nvim_rs::Neovim; use tokio::process::ChildStdin; #[cfg(windows)] -use crate::settings::windows_registry::{ +use crate::windows_utils::{ register_rightclick_directory, register_rightclick_file, unregister_rightclick, }; diff --git a/src/main.rs b/src/main.rs index 85b352a..9d65ddc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ mod redraw_scheduler; mod renderer; mod settings; mod window; +pub mod windows_utils; #[macro_use] extern crate derive_new; @@ -18,10 +19,7 @@ extern crate rust_embed; #[macro_use] extern crate lazy_static; -use std::{ - process, - sync::{atomic::AtomicBool, mpsc::channel, Arc}, -}; +use std::sync::{atomic::AtomicBool, mpsc::channel, Arc}; use crossfire::mpsc::unbounded_future; @@ -29,6 +27,7 @@ use bridge::start_bridge; use editor::start_editor; use renderer::{cursor_renderer::CursorSettings, RendererSettings}; use window::{create_window, window_geometry, KeyboardSettings, WindowSettings}; +use windows_utils::attach_parent_console; pub const INITIAL_DIMENSIONS: (u64, u64) = (100, 50); @@ -101,11 +100,22 @@ fn main() { // another frame next frame, or if it can safely skip drawing to save battery and cpu power. // Multiple other parts of the app "queue_next_frame" function to ensure animations continue // properly or updates to the graphics are pushed to the screen. + println!("This is a test"); + + if std::env::args().any(|arg| arg == "--version" || arg == "-v") { + attach_parent_console(); + println!("Neovide version: {}", env!("CARGO_PKG_VERSION")); + } + + if std::env::args().any(|arg| arg == "--help" || arg == "-h") { + attach_parent_console(); + println!("Neovide: {}", env!("CARGO_PKG_DESCRIPTION")); + } if let Err(err) = window_geometry() { eprintln!("{}", err); - process::exit(1); - }; + return; + } #[cfg(target_os = "macos")] { @@ -118,7 +128,6 @@ fn main() { .arg("--disowned") .spawn() .is_ok()); - std::process::exit(0); } else { eprintln!("error in disowning process, cannot obtain the path for the current executable, continuing without disowning..."); } diff --git a/src/settings/mod.rs b/src/settings/mod.rs index feee379..2f0a57f 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -12,7 +12,6 @@ use nvim_rs::Neovim; use parking_lot::RwLock; pub use rmpv::Value; use tokio::process::ChildStdin; -pub mod windows_registry; use crate::error_handling::ResultPanicExplanation; @@ -50,14 +49,12 @@ impl Settings { if arg == "--log" { log_to_file = true; false - } else if arg == "--version" || arg == "-v" { - println!("Neovide version: {}", env!("CARGO_PKG_VERSION")); - std::process::exit(0); - } else if arg == "--help" || arg == "-h" { - println!("neovide: {}", env!("CARGO_PKG_DESCRIPTION")); - std::process::exit(0); } else { !(arg.starts_with("--geometry=") + || arg == "--version" + || arg == "-v" + || arg == "--help" + || arg == "-h" || arg == "--wsl" || arg == "--disowned" || arg == "--multiGrid" diff --git a/src/settings/windows_registry.rs b/src/windows_utils.rs similarity index 97% rename from src/settings/windows_registry.rs rename to src/windows_utils.rs index 6386236..75ac405 100644 --- a/src/settings/windows_registry.rs +++ b/src/windows_utils.rs @@ -5,6 +5,7 @@ use winapi::{ shared::minwindef::{DWORD, HKEY, MAX_PATH}, um::{ libloaderapi::GetModuleFileNameA, + wincon::{AttachConsole, ATTACH_PARENT_PROCESS}, winnt::{KEY_WRITE, REG_OPTION_NON_VOLATILE, REG_SZ}, winreg::{RegCloseKey, RegCreateKeyExA, RegDeleteTreeA, RegSetValueExA, HKEY_CLASSES_ROOT}, }, @@ -212,3 +213,9 @@ pub fn register_rightclick_file() -> bool { } true } + +pub fn attach_parent_console() { + unsafe { + AttachConsole(ATTACH_PARENT_PROCESS); + } +}