diff --git a/crates/hyperlog-tui/src/app/dialog.rs b/crates/hyperlog-tui/src/app/dialog.rs index fcf29da..a3d9e75 100644 --- a/crates/hyperlog-tui/src/app/dialog.rs +++ b/crates/hyperlog-tui/src/app/dialog.rs @@ -251,7 +251,7 @@ impl CreateItemState { if !title.is_empty() { let mut path = self.path.clone(); - path.push(title.replace(' ', "").replace('.', "-")); + path.push(title.replace([' ', '.'], "-")); Some(hyperlog_core::commander::Command::CreateItem { root: self.root.clone(), @@ -270,18 +270,6 @@ impl CreateItemState { pub struct CreateItem {} impl StatefulWidget for &mut CreateItem { - // fn render(self, area: Rect, buf: &mut Buffer) - // where - // Self: Sized, - // { - // //buf.reset(); - - // // let block = Block::bordered() - // // .title("create item") - // // .padding(Padding::proportional(1)); - - // } - type State = CreateItemState; fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { @@ -306,9 +294,5 @@ impl StatefulWidget for &mut CreateItem { title_input.render(chunks[1], buf, &mut state.title); description_input.render(chunks[2], buf, &mut state.description); - - // let title = Paragraph::new("something"); //.block(block); - - // title.render(area, buf); } } diff --git a/crates/hyperlog-tui/src/command_parser.rs b/crates/hyperlog-tui/src/command_parser.rs index 8b62bda..4e348b9 100644 --- a/crates/hyperlog-tui/src/command_parser.rs +++ b/crates/hyperlog-tui/src/command_parser.rs @@ -5,6 +5,7 @@ pub enum Commands { Quit, WriteQuit, Archive, + CreateSection { name: String }, } impl Commands { @@ -26,11 +27,14 @@ impl CommandParser { let parts = prepared.split_whitespace().collect_vec(); match parts.split_first() { - Some((command, _)) => match *command { + Some((command, rest)) => match *command { "w" | "write" => Some(Commands::Write), "q" | "quit" => Some(Commands::Quit), "wq" | "write-quit" => Some(Commands::WriteQuit), "a" | "archive" => Some(Commands::Archive), + "cs" | "create-section" => rest.first().map(|name| Commands::CreateSection { + name: name.to_string(), + }), _ => None, }, None => None, diff --git a/crates/hyperlog-tui/src/components.rs b/crates/hyperlog-tui/src/components.rs index 1080776..f466f53 100644 --- a/crates/hyperlog-tui/src/components.rs +++ b/crates/hyperlog-tui/src/components.rs @@ -36,6 +36,8 @@ impl<'a> GraphExplorer<'a> { } pub fn update_graph(&mut self) -> Result<&mut Self> { + let now = std::time::SystemTime::now(); + let graph = self .state .querier @@ -50,6 +52,9 @@ impl<'a> GraphExplorer<'a> { self.inner.graph = Some(graph); + let elapsed = now.elapsed()?; + tracing::trace!("Graph.update_graph took: {}nanos", elapsed.as_nanos()); + Ok(self) } @@ -141,10 +146,26 @@ impl<'a> GraphExplorer<'a> { } pub fn execute_command(&mut self, command: &Commands) -> anyhow::Result<()> { - if let Commands::Archive = command { - if !self.get_current_path().is_empty() { - tracing::debug!("archiving path: {:?}", self.get_current_path()) + match command { + Commands::Archive => { + if !self.get_current_path().is_empty() { + tracing::debug!("archiving path: {:?}", self.get_current_path()) + } } + Commands::CreateSection { name } => { + if !name.is_empty() { + let mut path = self.get_current_path(); + path.push(name.replace(" ", "-").replace(".", "-")); + + self.state.commander.execute( + hyperlog_core::commander::Command::CreateSection { + root: self.inner.root.clone(), + path, + }, + )?; + } + } + _ => (), } self.update_graph()?;