pub mod python;
pub mod shell;
#[cfg(test)]
mod spike;
use gpui::{
App, TitlebarOptions, WindowBackgroundAppearance, WindowBounds, WindowDecorations, WindowOptions,
application, bounds, point, prelude::*, px, size,
};
pub use shell::{Shell, ShellModel};
#[cfg(test)]
pub(crate) static PYTHON_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
#[derive(Debug, Clone)]
pub struct HostConfig {
pub app_name: String,
pub python_paths: Vec<std::path::PathBuf>,
pub mods_paths: Vec<std::path::PathBuf>,
pub entry_module: String,
}
impl Default for HostConfig {
fn default() -> Self {
Self {
app_name: "FerroCAD".to_string(),
python_paths: Vec::new(),
mods_paths: Vec::new(),
entry_module: "ferrocad_shell".to_string(),
}
}
}
pub fn run() {
run_with(HostConfig::default());
}
pub fn run_with(config: HostConfig) {
python::configure(&config.entry_module, &config.python_paths, &config.mods_paths);
let model = match Shell::boot() {
Ok(model) => model,
Err(e) => {
eprintln!("ferrocad: failed to start: {e}");
std::process::exit(1);
}
};
application().run(move |cx: &mut App| {
let model = model.clone();
cx.open_window(window_options(&config), move |window, cx| {
let shell = cx.new(|cx| Shell::from_model(model.clone(), cx));
let console = shell.read(cx).console_focus_handle(cx);
window.focus(&console, cx);
shell
})
.unwrap();
});
}
fn window_options(config: &HostConfig) -> WindowOptions {
WindowOptions {
titlebar: Some(TitlebarOptions {
title: Some(config.app_name.clone().into()),
appears_transparent: true,
..Default::default()
}),
window_background: WindowBackgroundAppearance::Opaque,
window_decorations: Some(WindowDecorations::Client),
is_movable: true,
is_resizable: true,
app_owns_titlebar_drag: true,
window_bounds: Some(WindowBounds::Windowed(bounds(
point(px(80.), px(80.)),
size(px(1180.), px(760.)),
))),
..Default::default()
}
}