//! Filaments //! My personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities. use std::{process, sync::Arc}; use crate::{cli::Cli, config::Config, deimos::Deimos, tui::TuiApp, viz::FilViz}; use clap::Parser; use fil_core::{Kasten, KastenHandle}; use tokio::sync::{RwLock, mpsc}; use tracing::debug; mod cli; mod config; mod deimos; mod errors; mod filaments; mod logging; mod lsp; mod server; mod tui; mod viz; fn main() -> color_eyre::Result<()> { let args = Cli::parse(); // we only want to enable logging into stderr if we are serving let is_serve = matches!(args.command, Some(cli::Commands::Serve)); errors::init()?; logging::init(is_serve)?; let rt = Arc::new(tokio::runtime::Runtime::new()?); // Handle commands if let Some(command) = args.command { return rt.block_on(async { command.process().await }); } // some need a kasten handle and some dont, some need // Kasten //WARN: this needs to be removed let kh: KastenHandle = rt.block_on(async { let cfg = Config::parse()?; debug!("Config: {cfg:#?}"); Ok::(Arc::new(RwLock::new( Kasten::instansiate(cfg.fil_dir).await?, ))) })?; // what if we make this kasten handle optional and then pass that optional in. debug!("Kasten Handle: {kh:#?}"); let (signal_tx, signal_rx) = mpsc::unbounded_channel(); // Spawn TUI in its own thread let tui_handle = std::thread::spawn({ let tui_rt = rt.clone(); let kh = kh.clone(); let signal_tx = signal_tx.clone(); move || -> color_eyre::Result<()> { tui_rt.block_on(async { let mut tui = TuiApp::new(args.tick_rate, args.frame_rate, kh, signal_tx)?; tui.run().await?; // Force close everything once TUI is done. process::exit(0); }) } }); if args.visualizer { // Enter the guard so `egui_async` works properly let _rt_guard = rt.enter(); // spawn Deimos: file watcher { let kh = kh.clone(); rt.spawn(async { let deimos = Deimos::new(kh, signal_tx); deimos.watch().await }); } // Create an Index of the current contents let index = rt.block_on(async { kh.read().await.index.clone() }); // run the visualizer FilViz::run(kh, signal_rx, &index)?; } tui_handle.join().unwrap()?; Ok(()) }