diff --git a/crates/hyperlog-tui/src/command_parser.rs b/crates/hyperlog-tui/src/command_parser.rs index 272454a..db9fcdc 100644 --- a/crates/hyperlog-tui/src/command_parser.rs +++ b/crates/hyperlog-tui/src/command_parser.rs @@ -6,6 +6,7 @@ pub enum Commands { WriteQuit, Archive, CreateSection { name: String }, + CreateItem { name: String }, Edit, ShowAll, @@ -40,6 +41,9 @@ impl CommandParser { "cs" | "create-section" => rest.first().map(|name| Commands::CreateSection { name: name.to_string(), }), + "ci" | "create-item" => Some(Commands::CreateItem { + name: rest.join(" ").to_string(), + }), "e" | "edit" => Some(Commands::Edit), "show-all" => Some(Commands::ShowAll), "hide-done" => Some(Commands::HideDone), diff --git a/crates/hyperlog-tui/src/components/graph_explorer.rs b/crates/hyperlog-tui/src/components/graph_explorer.rs index e5bf033..fffec01 100644 --- a/crates/hyperlog-tui/src/components/graph_explorer.rs +++ b/crates/hyperlog-tui/src/components/graph_explorer.rs @@ -6,7 +6,8 @@ use ratatui::{prelude::*, widgets::*}; use crate::{ command_parser::Commands, commands::{ - batch::BatchCommand, create_section::CreateSectionCommandExt, + batch::BatchCommand, create_item::CreateItemCommandExt, + create_section::CreateSectionCommandExt, open_update_item_dialog::OpenUpdateItemDialogCommandExt, toggle_item::ToggleItemCommandExt, update_graph::UpdateGraphCommandExt, Command, IntoCommand, }, @@ -241,7 +242,7 @@ impl<'a> GraphExplorer<'a> { Commands::CreateSection { name } => { if !name.is_empty() { let mut path = self.get_current_path(); - path.push(name.replace(" ", "-").replace(".", "-")); + path.push(name.replace(".", "-")); // self.state // .commander @@ -258,6 +259,21 @@ impl<'a> GraphExplorer<'a> { batch.with(cmd.into_command()); } } + Commands::CreateItem { name } => { + if !name.is_empty() { + let mut path = self.get_current_path(); + path.push(name.replace(".", " ")); + let cmd = self.state.create_item_command().command( + &self.inner.root, + &path.iter().map(|i| i.as_str()).collect_vec(), + name, + "", + &hyperlog_core::log::ItemState::default(), + ); + + batch.with(cmd.into_command()); + } + } Commands::Edit => { if let Some(item) = self.get_current_item() { let path = self.get_current_path();