From d53ef9aa1bdbbb537fb005b53116c0dbd8e6a3e2 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sun, 13 Apr 2025 11:58:28 -0400 Subject: [PATCH] Launch clide in separate process by default. Improve CLI to support tui and gui modes. Also supports attaching the GUI to the current terminal via -g --- src/main.rs | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1b35fab..ab1c84b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use cxx_qt_lib::QString; use std::error::Error; +use std::process::{Command, Stdio}; use structopt::StructOpt; pub mod colors; @@ -34,16 +35,23 @@ fn run_tui(root_path: std::path::PathBuf) -> Result<(), Box> { Ok(()) } +/// Command line interface IDE with full GUI and headless modes. +/// If no flags are provided the GUI editor is launched in a separate process. +/// If no path is provided the current directory is used. #[derive(StructOpt, Debug)] -#[structopt(name = "clide")] +#[structopt(name = "clide", verbatim_doc_comment)] struct Cli { - /// The root path to open with the clide editor. + /// The root directory for the project to open with the clide editor. #[structopt(parse(from_os_str))] pub path: Option, - /// Run in headless mode if this flag is present. + /// Run clide in headless mode. #[structopt(name = "tui", short, long)] pub tui: bool, + + /// Run the clide GUI in the current process, blocking the terminal and showing all output streams. + #[structopt(name = "gui", short, long)] + pub gui: bool, } fn main() -> Result<(), Box> { @@ -58,9 +66,23 @@ fn main() -> Result<(), Box> { dirs::home_dir().expect("Failed to access filesystem.")), }; - // Open the TUI editor if requested, otherwise use the QML GUI by default. - match args.tui { - true => run_tui(root_path), - false => run_gui(root_path), + match args.gui { + true => run_gui(root_path), + false => { + // Open the TUI editor if requested, otherwise use the QML GUI by default. + match args.tui { + true => run_tui(root_path), + false => { + // Relaunch the CLIDE GUI in a separate process. + Command::new(std::env::current_exe()?) + .args(&["--gui"]) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .stdin(Stdio::null()) + .spawn()?; + Ok(()) + } + } + } } }