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
This commit is contained in:
parent
a29ae43e84
commit
d53ef9aa1b
30
src/main.rs
30
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<dyn Error>> {
|
||||
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<std::path::PathBuf>,
|
||||
|
||||
/// 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<dyn Error>> {
|
||||
@ -58,9 +66,23 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
dirs::home_dir().expect("Failed to access filesystem.")),
|
||||
};
|
||||
|
||||
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 => run_gui(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(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user