Skip to content

Commit

Permalink
feat(journal): output content to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Feb 7, 2024
1 parent d2f285c commit 80542f7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rust/logseq/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}

Expand All @@ -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(())
Expand Down

0 comments on commit 80542f7

Please sign in to comment.