Skip to content

Commit

Permalink
From-date option for graphing
Browse files Browse the repository at this point in the history
  • Loading branch information
mfep committed Jul 2, 2022
1 parent c303f4a commit 2627653
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/graphing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = &[
Expand Down Expand Up @@ -51,8 +52,9 @@ pub fn pretty_print_diary_rows(
if let Some(row) = current_row {
ret += &pretty_print_row(&current_date, row);
} else {
ret += &format!(
"{} !date missing from diary!\n",
_ = writeln!(
ret,
"{} !date missing from diary!",
current_date.format(datafile::DATE_FORMAT)
);
}
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
},

/// Queries for habit information on the specified date.
Insert {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2627653

Please sign in to comment.