diff --git a/.harper-dictionary.txt b/.harper-dictionary.txt index bc4c2be..01a830e 100644 --- a/.harper-dictionary.txt +++ b/.harper-dictionary.txt @@ -2,6 +2,8 @@ Implementers Multi-Device OS PKM +TODO's +Zettels clippy dir env diff --git a/doc/cleanup.md b/doc/cleanup.md index 842e682..38b602e 100644 --- a/doc/cleanup.md +++ b/doc/cleanup.md @@ -5,3 +5,6 @@ documentation = "https://suri.codes/projects/filaments" I need to rework my website to have a place for filaments, but then again, I don't really care about other people using my project, so i guess it really depends + + +Todo: do change based rendering... diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 6b2b194..167183b 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -7,6 +7,7 @@ mod process; #[derive(Parser, Debug)] #[command(author, version = version(), about)] +/// Command line arguments for `Filaments` pub struct Cli { /// Tick rate, i.e. number of ticks per second #[arg(short, long, value_name = "FLOAT", default_value_t = 4.0)] @@ -30,21 +31,13 @@ pub enum Commands { #[command(subcommand)] Zettel(ZettelSubcommand), + /// Manage TODO's #[command(subcommand)] Todo(TodoSubcommand), /// Spawn the `LSP` Lsp, - // / Manage TARS groups. - // #[command(subcommand)] - // Group(GroupSubcommand), - - // / Manage TARS tasks. - // #[command(subcommand)] - // Task(TaskSubcommand), - // - // /// Initalize Filaments. /// /// This will write a default config to ~/.config/filaments, @@ -55,23 +48,18 @@ pub enum Commands { #[arg(default_value = "ZettelKasten")] name: String, }, - // NOTE: By default the importer will fill in fields with - // default values if they arent present / aren't able to be - // parsed properly - // Import(ImportArgs), - Test, } #[derive(Subcommand, Debug)] /// Subcommand to manage Zettels. pub enum ZettelSubcommand { - /// Add a group. + /// Create a new `Zettel` New { #[arg(short, long)] - /// The file-path for data to pe put into. + /// The name of the `Zettel` title: String, }, - /// List groups. + /// List all Zettel's. List { /// Filter by tag #[arg(short = 't', long)] @@ -80,46 +68,31 @@ pub enum ZettelSubcommand { } #[derive(Subcommand, Debug)] -/// Subcommand to manage To-Do functionality +/// Subcommand to manage TODO functionality pub enum TodoSubcommand { + /// Manage `Group`s Group { - /// The name of this group + /// The name of this `Group` #[arg(short, long)] name: String, - /// If this group has a parent, provide the parent id. + /// If this `Group` has a parent, provide the parent id. #[arg(short, long)] parent_id: Option, }, + /// Manage `Task`s Task { - /// Name of the task + /// Name of the `Task` #[arg(short, long)] name: String, - /// Parent group of the task + /// Parent `Group` id of the `Task` #[arg(short, long)] parent_id: NanoId, }, } -// #[derive(Subcommand, Debug)] -// /// Subcommand to manage tars groups. -// pub enum GroupSubcommand { -// /// Add a group. -// Add(GroupAddArgs), -// /// List groups. -// List(GroupListArgs), -// } - -// #[derive(Debug, Args)] -// pub struct ExportArgs { -// #[arg(short, long, default_value = "./tars.json")] -// /// The file-path for data to pe put into. -// pub out_file: PathBuf, -// } -// - const VERSION_MESSAGE: &str = concat!( env!("CARGO_PKG_VERSION"), "-", @@ -132,7 +105,6 @@ const VERSION_MESSAGE: &str = concat!( pub fn version() -> String { let author = clap::crate_authors!(); - // let current_exe_path = PathBuf::from(clap::crate_name!()).display().to_string(); let config_dir_path = get_config_dir().display().to_string(); let data_dir_path = get_data_dir().display().to_string(); diff --git a/src/cli/process.rs b/src/cli/process.rs index 6d34212..3daa1db 100644 --- a/src/cli/process.rs +++ b/src/cli/process.rs @@ -18,17 +18,16 @@ impl Commands { pub async fn process(self) -> Result<()> { match self { Self::Init { name } => { - // create the directory let dir = current_dir() .context("Failed to get current directory")? .join(&name); Kasten::initialize(dir.clone()).await?; - // write config that sets the filaments directory to current dir! + // Write config that sets the filaments directory to current Dir! let config_str = dbg! {Config::generate(&dir)}?; - // create the config dir + // create the config Dir let config_dir = get_config_dir(); create_dir_all(config_dir).expect("creating the config dir should not error"); @@ -40,7 +39,6 @@ impl Commands { println!("wrote config to {config_file:#?}"); - // report status! println!("Initialized successfully!"); } @@ -53,20 +51,25 @@ impl Commands { let zettel = Zettel::new(title, &mut kt, vec![]).await?; println!("Zettel Created! {zettel:#?}"); } - ZettelSubcommand::List { by_tag: _by_tag } => {} + ZettelSubcommand::List { by_tag: _by_tag } => { + unimplemented!() + } } } + Self::Lsp => { + // parse a Kasten let conf = Config::parse().with_context(|| "Failed to parse the config!!")?; let kt = Kasten::instansiate(conf.fil_dir) .await .with_context(|| "Failed to initialize a kasten!!")?; + // get the in and out let stdin = tokio::io::stdin(); let stdout = tokio::io::stdout(); + // start the LSP let (service, socket) = LspService::new(|client| Backend::new(client, kt)); - Server::new(stdin, stdout, socket).serve(service).await; } @@ -76,22 +79,17 @@ impl Commands { match command { super::TodoSubcommand::Group { name, parent_id } => { - // lets create a tag for this first group first let group = Group::new(name, parent_id, &mut kt).await?; println!("created group {group:#?}"); } super::TodoSubcommand::Task { name, parent_id } => { + //TODO: need to expose the due date and priority through the CLI let task = Task::new(name, parent_id, &mut kt, None, Priority::default()).await?; println!("created task {task:#?}"); } } } - Self::Test => { - let conf = Config::parse()?; - let kt = Kasten::instansiate(conf.fil_dir).await?; - println!("kt: {kt:#?}"); - } } Ok(()) diff --git a/src/errors.rs b/src/errors.rs index e8bd80c..9f80e9e 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -8,7 +8,7 @@ use crossterm::{ /// Sets the panic-hook to be customized color-eyre `panic_hook`. /// -/// Additionally the panic handler prints different information +/// Additionally, the panic handler prints different information /// based on debug / release builds. pub fn init() -> color_eyre::Result<()> { let (_panic_hook, eyre_hook) = color_eyre::config::HookBuilder::default() @@ -23,7 +23,7 @@ pub fn init() -> color_eyre::Result<()> { eyre_hook.install()?; std::panic::set_hook(Box::new(move |panic_info| { - // exit from terminal if the app is in a terminal + // Exit from terminal if the app is in a terminal if crossterm::terminal::is_raw_mode_enabled().unwrap() { let _ = crossterm::execute!(stdout(), DisableBracketedPaste); let _ = crossterm::execute!(stdout(), DisableMouseCapture); diff --git a/src/logging.rs b/src/logging.rs index 21aa71c..f3e2874 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -4,7 +4,7 @@ use std::{ }; use color_eyre::eyre::Result; -use tracing::{Level, info}; +use tracing::Level; use tracing_error::ErrorLayer; use tracing_subscriber::{EnvFilter, Layer, fmt, layer::SubscriberExt, util::SubscriberInitExt}; @@ -24,8 +24,6 @@ pub static LOG_FILE: LazyLock = LazyLock::new(|| format!("{}.log", env!( pub fn init() -> Result<()> { let directory = config::get_data_dir(); - info!("{directory:#?}"); - create_dir_all(&directory)?; let log_path = directory.join(LOG_FILE.clone()); @@ -49,6 +47,7 @@ pub fn init() -> Result<()> { .with_target(false) .with_ansi(false) .with_filter(env_filter); + tracing_subscriber::registry() .with(file_subscriber) .with(ErrorLayer::default()) diff --git a/src/main.rs b/src/main.rs index f88de6e..acc42ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,15 +30,14 @@ fn main() -> color_eyre::Result<()> { let args = Cli::parse(); - // create a new tokio runtime, shared behind arc let rt = Arc::new(tokio::runtime::Runtime::new()?); - // if there are any commands, run those and exit + // Handle commands if let Some(command) = args.command { return rt.block_on(async { command.process().await }); } - // create the kasten handle + // Kasten let kh: KastenHandle = rt.block_on(async { let cfg = Config::parse()?; @@ -53,7 +52,7 @@ fn main() -> color_eyre::Result<()> { let (signal_tx, signal_rx) = mpsc::unbounded_channel(); - // then we spawn the tui on its own thread + // Spawn TUI in its own thread let tui_handle = std::thread::spawn({ let tui_rt = rt.clone(); let kh = kh.clone(); @@ -70,10 +69,10 @@ fn main() -> color_eyre::Result<()> { }); if args.visualizer { - // enter the guard so egui_async works properly + // Enter the guard so `egui_async` works properly let _rt_guard = rt.enter(); - // spawn deimos + // spawn Deimos: file watcher { let kh = kh.clone(); rt.spawn(async { @@ -82,12 +81,13 @@ fn main() -> color_eyre::Result<()> { }); } + // 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)?; } - // join on the tui tui_handle.join().unwrap()?; Ok(()) }