diff --git a/src/graphing.rs b/src/graphing.rs index 407714c..d939705 100644 --- a/src/graphing.rs +++ b/src/graphing.rs @@ -3,6 +3,7 @@ use crate::datafile; use crate::datafile::DiaryData; use anyhow::{bail, Result}; use chrono::NaiveDate; +use std::fmt::Write; use yansi::{Color, Paint}; const COLORS: &[Color] = &[ @@ -51,8 +52,9 @@ pub fn pretty_print_diary_rows( if let Some(row) = current_row { ret += &pretty_print_row(¤t_date, row); } else { - ret += &format!( - "{} !date missing from diary!\n", + _ = writeln!( + ret, + "{} !date missing from diary!", current_date.format(datafile::DATE_FORMAT) ); } @@ -130,7 +132,7 @@ fn generate_rows( } ret += " "; } - ret += &format!("{}\n", Paint::new(current_count).bold()); + _ = writeln!(ret, "{}", Paint::new(current_count).bold()); } } Ok(ret) diff --git a/src/main.rs b/src/main.rs index bb7b7b1..0dfa956 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,11 @@ enum Command { }, /// Displays the habit data according to the specified options to the terminal. - Graph, + Graph { + /// Start the graphing from this date. Must be in format YYYY-MM-DD. + #[structopt(long)] + from_date: Option, + }, /// Queries for habit information on the specified date. Insert { @@ -97,9 +101,11 @@ fn main() -> Result<()> { plot_datafile(&opt, &to_date, &data)?; } } - Command::Graph => { + Command::Graph { ref from_date } => { let data = datafile::parse_csv_to_diary_data(datafile_path)?; - plot_datafile(&opt, &Local::today().naive_local(), &data)?; + let from_date = parse_from_date(from_date)?; + let from_date = from_date.unwrap_or_else(|| Local::today().naive_local()); + plot_datafile(&opt, &from_date, &data)?; } Command::Insert { ref date, no_graph } => { let date = parse_from_date(&Some(date.clone()))?.unwrap();