From a77b96ddd1c2fb118aad785b6b7b452d71c61c20 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 20 Mar 2022 12:57:22 +0100 Subject: Don’t add a newline if there is no event in CLI This fixes counting 1 event when piping `wc -l`. --- src/cli/mod.rs | 6 +++--- src/main.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 88726ca..81c5895 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -2,7 +2,7 @@ use anyhow::Result; use chrono::Local; use rusqlite::Connection; -use crate::{db, model::event, model::event::Event}; +use crate::{db, model::event}; pub fn today(conn: &Connection) -> Result { let today = Local::today().naive_local(); @@ -15,7 +15,7 @@ pub fn today(conn: &Connection) -> Result { events.sort_by_key(|e| e.start); Ok(events .iter() - .map(Event::pprint) + .map(|e| format!("{}\n", e.pprint())) .collect::>() - .join("\n")) + .join("")) } diff --git a/src/main.rs b/src/main.rs index 83a0446..56a499c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ fn main() -> Result<()> { } = Opt::from_args(); let conn = db::init(&db_path)?; if list_today { - println!("{}", cli::today(&conn)?); + print!("{}", cli::today(&conn)?); } else { gui::run(conn); } -- cgit v1.2.3