diff --git a/src/cli.rs b/src/cli.rs index d54097f..d1d9005 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -86,8 +86,13 @@ fn find_entries(files: &Files, range: DateRange) -> Result, Error LineLayout { - layout::layout(entries, range, now) +fn find_layout( + files: &Files, + entries: &[Entry], + range: DateRange, + now: NaiveDateTime, +) -> LineLayout { + layout::layout(files, entries, range, now) } fn run_command( @@ -99,28 +104,28 @@ fn run_command( match &opt.command { None => { let entries = find_entries(files, range)?; - let layout = find_layout(&entries, range, now); + let layout = find_layout(files, &entries, range, now); print::print(&layout); } Some(Command::Show { entries: ns }) => { let entries = find_entries(files, range)?; - let layout = find_layout(&entries, range, now); + let layout = find_layout(files, &entries, range, now); show::show(files, &entries, &layout, ns)?; } Some(Command::Done { entries: ns }) => { let entries = find_entries(files, range)?; - let layout = find_layout(&entries, range, now); + let layout = find_layout(files, &entries, range, now); done::done(files, &entries, &layout, ns, now)?; let entries = find_entries(files, range)?; - let layout = find_layout(&entries, range, now); + let layout = find_layout(files, &entries, range, now); print::print(&layout); } Some(Command::Cancel { entries: ns }) => { let entries = find_entries(files, range)?; - let layout = find_layout(&entries, range, now); + let layout = find_layout(files, &entries, range, now); cancel::cancel(files, &entries, &layout, ns, now)?; let entries = find_entries(files, range)?; - let layout = find_layout(&entries, range, now); + let layout = find_layout(files, &entries, range, now); print::print(&layout); } Some(Command::Fmt) => files.mark_all_dirty(), diff --git a/src/cli/layout.rs b/src/cli/layout.rs index 9b8aa90..b063c44 100644 --- a/src/cli/layout.rs +++ b/src/cli/layout.rs @@ -1,6 +1,7 @@ use chrono::NaiveDateTime; use crate::eval::{DateRange, Entry}; +use crate::files::Files; use self::day::DayLayout; use self::line::LineLayout; @@ -8,12 +9,17 @@ use self::line::LineLayout; mod day; pub mod line; -pub fn layout(entries: &[Entry], range: DateRange, now: NaiveDateTime) -> LineLayout { +pub fn layout( + files: &Files, + entries: &[Entry], + range: DateRange, + now: NaiveDateTime, +) -> LineLayout { let mut day_layout = DayLayout::new(range, now); day_layout.layout(entries); let mut line_layout = LineLayout::new(); - line_layout.render(entries, &day_layout); + line_layout.render(files, entries, &day_layout); line_layout } diff --git a/src/cli/layout/line.rs b/src/cli/layout/line.rs index a1127a5..1236f8e 100644 --- a/src/cli/layout/line.rs +++ b/src/cli/layout/line.rs @@ -9,6 +9,7 @@ use chrono::NaiveDate; use crate::eval::{Entry, EntryKind}; use crate::files::primitives::Time; +use crate::files::Files; use super::super::error::Error; use super::day::{DayEntry, DayLayout}; @@ -69,6 +70,7 @@ pub enum LineEntry { spans: Vec>, date: NaiveDate, today: bool, + has_log: bool, }, Now { spans: Vec>, @@ -80,6 +82,7 @@ pub enum LineEntry { time: Times, kind: LineKind, text: String, + has_desc: bool, extra: Option, }, } @@ -107,7 +110,7 @@ impl LineLayout { } } - pub fn render(&mut self, entries: &[Entry], layout: &DayLayout) { + pub fn render(&mut self, files: &Files, entries: &[Entry], layout: &DayLayout) { // Make sure spans for visible `*End`s are drawn for entry in &layout.earlier { match entry { @@ -123,6 +126,7 @@ impl LineLayout { spans, date: day, today: day == layout.today, + has_log: files.log(day).is_some(), }); let layout_entries = layout.days.get(&day).expect("got nonexisting day"); @@ -291,6 +295,7 @@ impl LineLayout { time, kind: Self::entry_kind(entry), text: Self::entry_title(entry), + has_desc: entry.has_description, extra, }); } diff --git a/src/cli/print.rs b/src/cli/print.rs index 657cf1e..c644577 100644 --- a/src/cli/print.rs +++ b/src/cli/print.rs @@ -24,7 +24,12 @@ impl ShowLines { fn display_line(&mut self, line: &LineEntry) { match line { - LineEntry::Day { spans, date, today } => self.display_line_date(spans, *date, *today), + LineEntry::Day { + spans, + date, + today, + has_log, + } => self.display_line_date(spans, *date, *today, *has_log), LineEntry::Now { spans, time } => self.display_line_now(spans, *time), LineEntry::Entry { number, @@ -32,12 +37,19 @@ impl ShowLines { time, kind, text, + has_desc, extra, - } => self.display_line_entry(*number, spans, *time, *kind, text, extra), + } => self.display_line_entry(*number, spans, *time, *kind, text, *has_desc, extra), } } - fn display_line_date(&mut self, spans: &[Option], date: NaiveDate, today: bool) { + fn display_line_date( + &mut self, + spans: &[Option], + date: NaiveDate, + today: bool, + has_log: bool, + ) { let weekday: Weekday = date.weekday().into(); let weekday = weekday.full_name(); @@ -55,16 +67,23 @@ impl ShowLines { // Spans and filler '=' symbols let p2 = self.display_spans(spans, styled("=")); - // The rest of the line - let p3 = format!( - "=== {:9} {} ===={:=], time: Time) { @@ -84,6 +103,7 @@ impl ShowLines { time: Times, kind: LineKind, text: &str, + has_desc: bool, extra: &Option, ) { let num = match number { @@ -92,12 +112,13 @@ impl ShowLines { }; self.push(&format!( - "{:>nw$} {} {}{} {}{}\n", + "{:>nw$} {} {}{} {}{}{}\n", num.bright_black(), self.display_spans(spans, " ".into()), Self::display_kind(kind), Self::display_time(time), text, + Self::display_marker(has_desc, ""), Self::display_extra(extra), nw = self.num_width, )) @@ -140,6 +161,14 @@ impl ShowLines { } } + fn display_marker(marker: bool, otherwise: &str) -> ColoredString { + if marker { + "*".bright_yellow() + } else { + otherwise.into() + } + } + fn display_extra(extra: &Option) -> ColoredString { match extra { None => "".into(), diff --git a/src/files.rs b/src/files.rs index 6ced9ae..105010c 100644 --- a/src/files.rs +++ b/src/files.rs @@ -7,7 +7,7 @@ use chrono::{DateTime, NaiveDate, Utc}; use codespan_reporting::files::SimpleFiles; use tzfile::Tz; -use self::commands::{Command, Done, File}; +use self::commands::{Command, Done, File, Log}; pub use self::error::{Error, Result}; use self::primitives::Spanned; @@ -311,6 +311,14 @@ impl Files { Self::command_of_files(&self.files, source) } + pub fn log(&self, date: NaiveDate) -> Option<&Log> { + let source = *self.logs.get(&date)?; + match self.command(source).command { + Command::Log(log) => Some(log), + _ => unreachable!(), + } + } + pub fn now(&self) -> DateTime<&Tz> { if let Some(tz) = &self.timezone { Utc::now().with_timezone(&tz)