jrnl: add entry listing
This commit is contained in:
parent
83c0fac427
commit
78bb79e258
8 changed files with 524 additions and 658 deletions
207
programs/jrnl/Cargo.lock
generated
207
programs/jrnl/Cargo.lock
generated
|
@ -29,6 +29,21 @@ version = "0.2.18"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
|
||||
|
||||
[[package]]
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.13"
|
||||
|
@ -95,6 +110,12 @@ version = "2.5.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
|
||||
|
||||
[[package]]
|
||||
name = "cassowary"
|
||||
version = "0.3.0"
|
||||
|
@ -110,12 +131,32 @@ dependencies = [
|
|||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"wasm-bindgen",
|
||||
"windows-targets 0.52.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.4"
|
||||
|
@ -175,6 +216,12 @@ dependencies = [
|
|||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
|
||||
|
||||
[[package]]
|
||||
name = "crossterm"
|
||||
version = "0.27.0"
|
||||
|
@ -200,15 +247,6 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.3.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
|
||||
dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "5.0.1"
|
||||
|
@ -287,6 +325,29 @@ version = "0.5.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.2.6"
|
||||
|
@ -322,6 +383,7 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
|
|||
name = "jrnl"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
"dirs",
|
||||
"ego-tree",
|
||||
|
@ -329,7 +391,15 @@ dependencies = [
|
|||
"markdown",
|
||||
"petgraph",
|
||||
"ratatui",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -409,10 +479,13 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
name = "num-traits"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
|
@ -471,12 +544,6 @@ version = "0.5.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d15b6607fa632996eb8a17c9041cb6071cb75ac057abd45dece578723ea8c7c0"
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.80"
|
||||
|
@ -582,26 +649,6 @@ version = "1.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.198"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.198"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.3.17"
|
||||
|
@ -713,25 +760,6 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"num-conv",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
|
@ -768,6 +796,60 @@ version = "0.11.0+wasi-snapshot-preview1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
|
@ -790,6 +872,15 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
|
|
|
@ -4,12 +4,13 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.38"
|
||||
clap = { version = "4.5.4", features = ["derive", "env"] }
|
||||
dirs = "5.0.1"
|
||||
ego-tree = "0.6.2"
|
||||
indexmap = "2.2.6"
|
||||
markdown = "0.3.0"
|
||||
owo-colors = "4.0.0"
|
||||
petgraph = "0.6.4"
|
||||
ratatui = "0.26.2"
|
||||
time = { version = "0.3.36", features = ["parsing"]}
|
||||
time-macros = { version = "0.2.0-alpha.1" }
|
||||
termsize = "0.1.6"
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
use clap::{Parser, Subcommand};
|
||||
use std::{fs, path::PathBuf};
|
||||
use time::format_description::well_known::{iso8601, Iso8601};
|
||||
|
||||
use crate::md::Doc;
|
||||
|
||||
const DATETIME_CONFIG: iso8601::EncodedConfig = iso8601::Config::DEFAULT
|
||||
.set_time_precision(iso8601::TimePrecision::Minute {
|
||||
decimal_digits: None,
|
||||
})
|
||||
.encode();
|
||||
const DT_FORMAT: Iso8601<DATETIME_CONFIG> = Iso8601::<DATETIME_CONFIG>;
|
||||
use crate::{commands::list_entries::list_entries, md::Doc};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct Cli {
|
||||
|
@ -21,7 +13,8 @@ struct Cli {
|
|||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum Command {
|
||||
List,
|
||||
#[command(aliases = ["l", "ls", "list"])]
|
||||
ListEntries,
|
||||
Add,
|
||||
}
|
||||
|
||||
|
@ -30,23 +23,70 @@ fn main() {
|
|||
println!("Hello, world!");
|
||||
println!("cli: {cli:#?}");
|
||||
|
||||
// TODO: handle btter
|
||||
let file = fs::read_to_string(cli.s10e_jrnl_file_loc).unwrap();
|
||||
match cli.command {
|
||||
Some(Command::ListEntries) => list_entries(cli.s10e_jrnl_file_loc.clone()),
|
||||
Some(Command::Add) => todo!(),
|
||||
None => {
|
||||
// TODO: handle btter
|
||||
let file = fs::read_to_string(cli.s10e_jrnl_file_loc).unwrap();
|
||||
|
||||
let doc = Doc::new(&file);
|
||||
dbg!(doc);
|
||||
let doc = Doc::new(&file);
|
||||
dbg!(doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod utils {
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
pub fn format_datetime(ts: DateTime<FixedOffset>) -> String {
|
||||
ts.format("%A, %-d. %B %Y %R").to_string()
|
||||
}
|
||||
pub fn format_datetime_padded(ts: DateTime<FixedOffset>) -> String {
|
||||
format!(
|
||||
"{:>9}{}{:<9}{}",
|
||||
ts.format("%A, "),
|
||||
ts.format("%d. "),
|
||||
ts.format("%B"),
|
||||
ts.format(" %Y %R"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
mod commands {
|
||||
pub mod list_entries {
|
||||
use owo_colors::OwoColorize;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use crate::md::Doc;
|
||||
|
||||
pub fn list_entries(path: PathBuf) {
|
||||
let file = fs::read_to_string(path).unwrap();
|
||||
let doc = Doc::new(&file);
|
||||
|
||||
for (i, entry) in doc.entries.into_iter().enumerate() {
|
||||
let n = format!("{:>2}", i + 1);
|
||||
let r = format!(". {}", entry.title,);
|
||||
let l = format!(" {} ", crate::utils::format_datetime(entry.timestamp));
|
||||
let termsize::Size { cols, .. } = termsize::get().unwrap();
|
||||
|
||||
let padding = " ".repeat(cols as usize - (n.len() + r.len() + l.len()));
|
||||
|
||||
println!("{}{r}{padding}{}", n.cyan(), l.white())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod add_entry {}
|
||||
}
|
||||
|
||||
mod md {
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use markdown::{Block, Span};
|
||||
use time::PrimitiveDateTime;
|
||||
|
||||
use crate::DT_FORMAT;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Doc {
|
||||
title: Vec<Span>,
|
||||
entries: Vec<Entry>,
|
||||
pub title: Vec<Span>,
|
||||
pub entries: Vec<Entry>,
|
||||
}
|
||||
|
||||
impl Doc {
|
||||
|
@ -70,7 +110,8 @@ mod md {
|
|||
};
|
||||
|
||||
let (ts, entry_title) = title.split_once(": ").unwrap();
|
||||
let ts = PrimitiveDateTime::parse(ts, &DT_FORMAT).unwrap();
|
||||
let ts = DateTime::parse_from_rfc3339(ts).unwrap();
|
||||
// let ts = PrimitiveDateTime::parse(ts, &DT_FORMAT).unwrap();
|
||||
|
||||
current = Some(Entry {
|
||||
timestamp: ts,
|
||||
|
@ -81,6 +122,9 @@ mod md {
|
|||
other => current.as_mut().unwrap().content.push(other),
|
||||
}
|
||||
}
|
||||
if let Some(cur) = current {
|
||||
entries.push(cur);
|
||||
}
|
||||
|
||||
Self {
|
||||
title: doc_title,
|
||||
|
@ -91,8 +135,8 @@ mod md {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct Entry {
|
||||
timestamp: PrimitiveDateTime,
|
||||
title: String,
|
||||
content: Vec<Block>,
|
||||
pub timestamp: DateTime<FixedOffset>,
|
||||
pub title: String,
|
||||
pub content: Vec<Block>,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue