diff --git a/Cargo.toml b/Cargo.toml index d98d6ee..f4979f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "memo-cli" -version = "0.1.1" +version = "0.2.0" authors = ["alemidev "] description = "A simple CLI tool to help you remember things" repository = "https://github.com/alemidev/memo-cli" diff --git a/src/categorize.rs b/src/categorize.rs index ca6d89c..399e926 100644 --- a/src/categorize.rs +++ b/src/categorize.rs @@ -20,7 +20,8 @@ impl Tree { } } -pub fn format_tree(node: &MemoNode, depth: i32, colored: bool) -> String { +pub fn format_tree(node: &MemoNode, depth: i32, colored: bool, max_depth: i32) -> String { + if depth >= max_depth { return "".to_string(); } let mut out = "".to_string(); let mut prefix = "".to_string(); // TODO string builder? for i in 0..depth { @@ -45,7 +46,7 @@ pub fn format_tree(node: &MemoNode, depth: i32, colored: bool) -> String { for sub in &node.sub { let sep = if colored { "┐".bright_black().to_string() } else { "┐".to_string() }; out.push_str(format!("{}{} #{}\n", prefix, sep, sub.tag).as_str()); - out.push_str(format_tree(sub, depth + 1, colored).as_str()); + out.push_str(format_tree(sub, depth + 1, colored, max_depth).as_str()); } // if prefix.len() > 0 { diff --git a/src/main.rs b/src/main.rs index a61c55d..24e30c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,6 +62,8 @@ enum Commands { tag: Option, #[clap(short, long, help = "show memos in a notification")] notify: bool, + #[clap(short, long, help = "limit how deep the memo tree is traversed", default_value_t = 20)] + depth: i32, #[clap(long, help = "show completed tasks")] old: bool, }, @@ -216,13 +218,13 @@ where T: StorageDriver, m_str, ); } - Some(Commands::List { tag, notify, old }) => { + Some(Commands::List { tag, notify, depth, old }) => { let all = storage.all(old).unwrap(); - display_memos(all, tag, &ctx, notify); + display_memos(all, tag, &ctx, notify, depth); }, None => { let all = storage.all(false).unwrap(); - display_memos(all, None, &ctx, false); + display_memos(all, None, &ctx, false, 5); } } @@ -245,7 +247,7 @@ where T: StorageDriver, Ok(()) } -fn display_memos(all: Vec, query: Option, ctx: &Context, notify: bool) { +fn display_memos(all: Vec, query: Option, ctx: &Context, notify: bool, max_depth: i32) { // let all = storage.all(args.old).unwrap(); let mut builder = String::new(); let timing = format!( @@ -264,7 +266,7 @@ fn display_memos(all: Vec, query: Option, ctx: &Context, notify: b if let Some(q) = query { tree_ref = traverse(tree_ref, q); } - builder.push_str(format_tree(tree_ref, 0, !notify).as_str()); + builder.push_str(format_tree(tree_ref, 0, !notify, max_depth).as_str()); if notify { Notification::new() .summary(format!("memo-cli | {}", timing).as_str()) diff --git a/src/storage/sqlite.rs b/src/storage/sqlite.rs index 80331fe..1cdd60f 100644 --- a/src/storage/sqlite.rs +++ b/src/storage/sqlite.rs @@ -37,8 +37,8 @@ impl SQLiteStorage { )?; connection.execute( "CREATE TABLE IF NOT EXISTS state ( - last_edit DATETIME DEFAULT NULL, - last_sync DATETIME DEFAULT NULL + last_edit DATETIME NOT NULL, + last_sync DATETIME DEFAULT NULL, last_memo TEXT DEFAULT NULL );", [], @@ -51,6 +51,11 @@ impl SQLiteStorage { // );", // [], // )?; + + connection.execute( + "INSERT INTO state (last_edit) VALUES (?)", + params![Utc::now()] + )?; } return Ok(SQLiteStorage { conn: connection , tmpfile: None }); @@ -131,8 +136,8 @@ impl StorageDriver for SQLiteStorage { let tx = self.conn.transaction()?; tx.execute("DELETE FROM memo WHERE id = ?", params![m.id.to_string()])?; tx.execute( - "INSERT INTO memo (id, body, due, done, last_edit) VALUES (?, ?, ?, ?, ?)", - params![m.id.to_string(), m.body, m.due, m.done, m.last_edit], + "INSERT INTO memo (id, tag, body, due, done, last_edit) VALUES (?, ?, ?, ?, ?, ?)", + params![m.id.to_string(), m.tag, m.body, m.due, m.done, m.last_edit], )?; tx.execute("UPDATE state SET last_edit = ?", params![Utc::now()])?; tx.commit()?;