feat: add create section
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-09 18:00:25 +02:00
parent 0406fbe14d
commit 105ab41f19
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
3 changed files with 30 additions and 21 deletions

View File

@ -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);
}
}

View File

@ -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,

View File

@ -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,11 +146,27 @@ impl<'a> GraphExplorer<'a> {
}
pub fn execute_command(&mut self, command: &Commands) -> anyhow::Result<()> {
if let Commands::Archive = command {
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()?;