Print markers for logs and entry descriptions
This commit is contained in:
parent
b3d81a8d0a
commit
4a46e70a73
5 changed files with 78 additions and 25 deletions
21
src/cli.rs
21
src/cli.rs
|
|
@ -86,8 +86,13 @@ fn find_entries(files: &Files, range: DateRange) -> Result<Vec<Entry>, Error<Fil
|
||||||
Ok(files.eval(EntryMode::Relevant, range)?)
|
Ok(files.eval(EntryMode::Relevant, range)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_layout(entries: &[Entry], range: DateRange, now: NaiveDateTime) -> LineLayout {
|
fn find_layout(
|
||||||
layout::layout(entries, range, now)
|
files: &Files,
|
||||||
|
entries: &[Entry],
|
||||||
|
range: DateRange,
|
||||||
|
now: NaiveDateTime,
|
||||||
|
) -> LineLayout {
|
||||||
|
layout::layout(files, entries, range, now)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_command(
|
fn run_command(
|
||||||
|
|
@ -99,28 +104,28 @@ fn run_command(
|
||||||
match &opt.command {
|
match &opt.command {
|
||||||
None => {
|
None => {
|
||||||
let entries = find_entries(files, range)?;
|
let entries = find_entries(files, range)?;
|
||||||
let layout = find_layout(&entries, range, now);
|
let layout = find_layout(files, &entries, range, now);
|
||||||
print::print(&layout);
|
print::print(&layout);
|
||||||
}
|
}
|
||||||
Some(Command::Show { entries: ns }) => {
|
Some(Command::Show { entries: ns }) => {
|
||||||
let entries = find_entries(files, range)?;
|
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)?;
|
show::show(files, &entries, &layout, ns)?;
|
||||||
}
|
}
|
||||||
Some(Command::Done { entries: ns }) => {
|
Some(Command::Done { entries: ns }) => {
|
||||||
let entries = find_entries(files, range)?;
|
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)?;
|
done::done(files, &entries, &layout, ns, now)?;
|
||||||
let entries = find_entries(files, range)?;
|
let entries = find_entries(files, range)?;
|
||||||
let layout = find_layout(&entries, range, now);
|
let layout = find_layout(files, &entries, range, now);
|
||||||
print::print(&layout);
|
print::print(&layout);
|
||||||
}
|
}
|
||||||
Some(Command::Cancel { entries: ns }) => {
|
Some(Command::Cancel { entries: ns }) => {
|
||||||
let entries = find_entries(files, range)?;
|
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)?;
|
cancel::cancel(files, &entries, &layout, ns, now)?;
|
||||||
let entries = find_entries(files, range)?;
|
let entries = find_entries(files, range)?;
|
||||||
let layout = find_layout(&entries, range, now);
|
let layout = find_layout(files, &entries, range, now);
|
||||||
print::print(&layout);
|
print::print(&layout);
|
||||||
}
|
}
|
||||||
Some(Command::Fmt) => files.mark_all_dirty(),
|
Some(Command::Fmt) => files.mark_all_dirty(),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
|
|
||||||
use crate::eval::{DateRange, Entry};
|
use crate::eval::{DateRange, Entry};
|
||||||
|
use crate::files::Files;
|
||||||
|
|
||||||
use self::day::DayLayout;
|
use self::day::DayLayout;
|
||||||
use self::line::LineLayout;
|
use self::line::LineLayout;
|
||||||
|
|
@ -8,12 +9,17 @@ use self::line::LineLayout;
|
||||||
mod day;
|
mod day;
|
||||||
pub mod line;
|
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);
|
let mut day_layout = DayLayout::new(range, now);
|
||||||
day_layout.layout(entries);
|
day_layout.layout(entries);
|
||||||
|
|
||||||
let mut line_layout = LineLayout::new();
|
let mut line_layout = LineLayout::new();
|
||||||
line_layout.render(entries, &day_layout);
|
line_layout.render(files, entries, &day_layout);
|
||||||
|
|
||||||
line_layout
|
line_layout
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use chrono::NaiveDate;
|
||||||
|
|
||||||
use crate::eval::{Entry, EntryKind};
|
use crate::eval::{Entry, EntryKind};
|
||||||
use crate::files::primitives::Time;
|
use crate::files::primitives::Time;
|
||||||
|
use crate::files::Files;
|
||||||
|
|
||||||
use super::super::error::Error;
|
use super::super::error::Error;
|
||||||
use super::day::{DayEntry, DayLayout};
|
use super::day::{DayEntry, DayLayout};
|
||||||
|
|
@ -69,6 +70,7 @@ pub enum LineEntry {
|
||||||
spans: Vec<Option<SpanSegment>>,
|
spans: Vec<Option<SpanSegment>>,
|
||||||
date: NaiveDate,
|
date: NaiveDate,
|
||||||
today: bool,
|
today: bool,
|
||||||
|
has_log: bool,
|
||||||
},
|
},
|
||||||
Now {
|
Now {
|
||||||
spans: Vec<Option<SpanSegment>>,
|
spans: Vec<Option<SpanSegment>>,
|
||||||
|
|
@ -80,6 +82,7 @@ pub enum LineEntry {
|
||||||
time: Times,
|
time: Times,
|
||||||
kind: LineKind,
|
kind: LineKind,
|
||||||
text: String,
|
text: String,
|
||||||
|
has_desc: bool,
|
||||||
extra: Option<String>,
|
extra: Option<String>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -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
|
// Make sure spans for visible `*End`s are drawn
|
||||||
for entry in &layout.earlier {
|
for entry in &layout.earlier {
|
||||||
match entry {
|
match entry {
|
||||||
|
|
@ -123,6 +126,7 @@ impl LineLayout {
|
||||||
spans,
|
spans,
|
||||||
date: day,
|
date: day,
|
||||||
today: day == layout.today,
|
today: day == layout.today,
|
||||||
|
has_log: files.log(day).is_some(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let layout_entries = layout.days.get(&day).expect("got nonexisting day");
|
let layout_entries = layout.days.get(&day).expect("got nonexisting day");
|
||||||
|
|
@ -291,6 +295,7 @@ impl LineLayout {
|
||||||
time,
|
time,
|
||||||
kind: Self::entry_kind(entry),
|
kind: Self::entry_kind(entry),
|
||||||
text: Self::entry_title(entry),
|
text: Self::entry_title(entry),
|
||||||
|
has_desc: entry.has_description,
|
||||||
extra,
|
extra,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,12 @@ impl ShowLines {
|
||||||
|
|
||||||
fn display_line(&mut self, line: &LineEntry) {
|
fn display_line(&mut self, line: &LineEntry) {
|
||||||
match line {
|
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::Now { spans, time } => self.display_line_now(spans, *time),
|
||||||
LineEntry::Entry {
|
LineEntry::Entry {
|
||||||
number,
|
number,
|
||||||
|
|
@ -32,12 +37,19 @@ impl ShowLines {
|
||||||
time,
|
time,
|
||||||
kind,
|
kind,
|
||||||
text,
|
text,
|
||||||
|
has_desc,
|
||||||
extra,
|
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<SpanSegment>], date: NaiveDate, today: bool) {
|
fn display_line_date(
|
||||||
|
&mut self,
|
||||||
|
spans: &[Option<SpanSegment>],
|
||||||
|
date: NaiveDate,
|
||||||
|
today: bool,
|
||||||
|
has_log: bool,
|
||||||
|
) {
|
||||||
let weekday: Weekday = date.weekday().into();
|
let weekday: Weekday = date.weekday().into();
|
||||||
let weekday = weekday.full_name();
|
let weekday = weekday.full_name();
|
||||||
|
|
||||||
|
|
@ -55,16 +67,23 @@ impl ShowLines {
|
||||||
// Spans and filler '=' symbols
|
// Spans and filler '=' symbols
|
||||||
let p2 = self.display_spans(spans, styled("="));
|
let p2 = self.display_spans(spans, styled("="));
|
||||||
|
|
||||||
// The rest of the line
|
// The rest of the line until after the date
|
||||||
let p3 = format!(
|
let p3 = format!("=== {:9} {}", weekday, date,);
|
||||||
"=== {:9} {} ===={:=<w$}",
|
|
||||||
weekday,
|
|
||||||
date,
|
|
||||||
"",
|
|
||||||
w = self.num_width + self.span_width
|
|
||||||
);
|
|
||||||
|
|
||||||
self.push(&format!("{}{}{}\n", styled(&p1), p2, styled(&p3)));
|
// The "has log" marker (if any)
|
||||||
|
let p4 = Self::display_marker(has_log, " ");
|
||||||
|
|
||||||
|
// The rest of the line
|
||||||
|
let p5 = format!(" ===={:=<w$}", "", w = self.num_width + self.span_width);
|
||||||
|
|
||||||
|
self.push(&format!(
|
||||||
|
"{}{}{}{}{}\n",
|
||||||
|
styled(&p1),
|
||||||
|
p2,
|
||||||
|
styled(&p3),
|
||||||
|
p4,
|
||||||
|
styled(&p5)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_line_now(&mut self, spans: &[Option<SpanSegment>], time: Time) {
|
fn display_line_now(&mut self, spans: &[Option<SpanSegment>], time: Time) {
|
||||||
|
|
@ -84,6 +103,7 @@ impl ShowLines {
|
||||||
time: Times,
|
time: Times,
|
||||||
kind: LineKind,
|
kind: LineKind,
|
||||||
text: &str,
|
text: &str,
|
||||||
|
has_desc: bool,
|
||||||
extra: &Option<String>,
|
extra: &Option<String>,
|
||||||
) {
|
) {
|
||||||
let num = match number {
|
let num = match number {
|
||||||
|
|
@ -92,12 +112,13 @@ impl ShowLines {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.push(&format!(
|
self.push(&format!(
|
||||||
"{:>nw$} {} {}{} {}{}\n",
|
"{:>nw$} {} {}{} {}{}{}\n",
|
||||||
num.bright_black(),
|
num.bright_black(),
|
||||||
self.display_spans(spans, " ".into()),
|
self.display_spans(spans, " ".into()),
|
||||||
Self::display_kind(kind),
|
Self::display_kind(kind),
|
||||||
Self::display_time(time),
|
Self::display_time(time),
|
||||||
text,
|
text,
|
||||||
|
Self::display_marker(has_desc, ""),
|
||||||
Self::display_extra(extra),
|
Self::display_extra(extra),
|
||||||
nw = self.num_width,
|
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<String>) -> ColoredString {
|
fn display_extra(extra: &Option<String>) -> ColoredString {
|
||||||
match extra {
|
match extra {
|
||||||
None => "".into(),
|
None => "".into(),
|
||||||
|
|
|
||||||
10
src/files.rs
10
src/files.rs
|
|
@ -7,7 +7,7 @@ use chrono::{DateTime, NaiveDate, Utc};
|
||||||
use codespan_reporting::files::SimpleFiles;
|
use codespan_reporting::files::SimpleFiles;
|
||||||
use tzfile::Tz;
|
use tzfile::Tz;
|
||||||
|
|
||||||
use self::commands::{Command, Done, File};
|
use self::commands::{Command, Done, File, Log};
|
||||||
pub use self::error::{Error, Result};
|
pub use self::error::{Error, Result};
|
||||||
use self::primitives::Spanned;
|
use self::primitives::Spanned;
|
||||||
|
|
||||||
|
|
@ -311,6 +311,14 @@ impl Files {
|
||||||
Self::command_of_files(&self.files, source)
|
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> {
|
pub fn now(&self) -> DateTime<&Tz> {
|
||||||
if let Some(tz) = &self.timezone {
|
if let Some(tz) = &self.timezone {
|
||||||
Utc::now().with_timezone(&tz)
|
Utc::now().with_timezone(&tz)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue