2025-03-29 16:55:26 -04:00
|
|
|
// TODO: Header
|
2025-03-29 08:01:13 -04:00
|
|
|
|
2025-03-30 11:20:21 -04:00
|
|
|
use cxx_qt_lib::QString;
|
2025-04-13 09:35:55 -04:00
|
|
|
use std::error::Error;
|
2025-04-13 10:20:43 -04:00
|
|
|
use structopt::StructOpt;
|
2025-03-30 11:20:21 -04:00
|
|
|
|
|
|
|
|
pub mod colors;
|
2025-03-30 13:14:58 -04:00
|
|
|
pub mod filesystem;
|
2025-03-29 08:01:13 -04:00
|
|
|
|
2025-04-13 10:20:43 -04:00
|
|
|
fn run_gui(root_path: std::path::PathBuf) -> Result<(), Box<dyn Error>> {
|
|
|
|
|
println!("Starting the GUI editor at {:?}", root_path);
|
|
|
|
|
|
2025-03-29 08:01:13 -04:00
|
|
|
use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};
|
|
|
|
|
|
|
|
|
|
let mut app = QGuiApplication::new();
|
|
|
|
|
let mut engine = QQmlApplicationEngine::new();
|
|
|
|
|
|
2025-03-30 11:20:21 -04:00
|
|
|
if let Some(engine) = engine.as_mut() {
|
|
|
|
|
engine.add_import_path(&QString::from("qml/"));
|
|
|
|
|
}
|
2025-03-29 08:01:13 -04:00
|
|
|
if let Some(engine) = engine.as_mut() {
|
|
|
|
|
engine.load(&QUrl::from("qml/main.qml"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(app) = app.as_mut() {
|
|
|
|
|
app.exec();
|
|
|
|
|
}
|
2025-04-13 09:35:55 -04:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-13 10:20:43 -04:00
|
|
|
fn run_tui(root_path: std::path::PathBuf) -> Result<(), Box<dyn Error>> {
|
|
|
|
|
println!("Starting the TUI editor at {:?}", root_path);
|
2025-04-13 09:35:55 -04:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-13 10:20:43 -04:00
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
|
|
#[structopt(name = "clide")]
|
|
|
|
|
struct Cli {
|
|
|
|
|
/// The root path 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.
|
|
|
|
|
#[structopt(name = "tui", short, long)]
|
|
|
|
|
pub tui: bool,
|
2025-04-13 09:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
2025-04-13 10:20:43 -04:00
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
let args = Cli::from_args();
|
2025-04-13 09:35:55 -04:00
|
|
|
|
2025-04-13 10:20:43 -04:00
|
|
|
// If the CLI was provided a directory to open use it.
|
|
|
|
|
// Otherwise, attempt to find the home directory. If that fails use CWD.
|
|
|
|
|
let root_path = args
|
|
|
|
|
.path
|
|
|
|
|
.or_else(dirs::home_dir)
|
|
|
|
|
.unwrap_or_else(|| std::env::current_dir().expect("Failed to access filesystem."));
|
2025-04-13 09:35:55 -04:00
|
|
|
|
2025-04-13 10:20:43 -04:00
|
|
|
// 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),
|
2025-04-13 09:35:55 -04:00
|
|
|
}
|
2025-03-29 08:01:13 -04:00
|
|
|
}
|