From 80542f71274e9f0c0f05adbd473407ce8238b822 Mon Sep 17 00:00:00 2001 From: "W. Augusto Andreoli" Date: Wed, 7 Feb 2024 11:38:58 +0100 Subject: [PATCH] feat(journal): output content to stdout #17 --- rust/logseq/src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rust/logseq/src/lib.rs b/rust/logseq/src/lib.rs index 4117c20..020b7a7 100644 --- a/rust/logseq/src/lib.rs +++ b/rust/logseq/src/lib.rs @@ -86,10 +86,11 @@ impl Journal { /// Appends the given Markdown content to the journal file pub fn append(&self, markdown: String) -> anyhow::Result<()> { let path = self.as_path(); + eprint!("Journal {}: ", path.to_string_lossy()); // if no markdown content, print an error and return if markdown.is_empty() { - eprintln!("No content to append to {:?}", path); + eprintln!("no content provided"); return Ok(()); } @@ -109,13 +110,16 @@ impl Journal { .create(true) .truncate(true) .open(&path)?; - eprintln!("New journal file {:?}", path); + eprintln!("new/recreated file"); } else { file = OpenOptions::new().append(true).open(&path)?; - eprintln!("Appending to {:?}", path); + eprintln!("appending"); + + println!(); // Output all content to stdout file.write_all(b"\n")?; } + print!("{}", markdown); file.write_all(markdown.as_bytes())?; file.flush()?; Ok(())