Add marks to show which span a reminder belongs to

This commit is contained in:
Joscha 2022-11-01 16:41:37 +01:00
parent 23b0a5e5fc
commit f3792fae64
3 changed files with 19 additions and 1 deletions

View file

@ -4,6 +4,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased
### Added
- Marks to show which span a reminder belongs to
### Changed
- Birthdays for current day are now highlighted
- Default value for `--range` argument

View file

@ -36,6 +36,7 @@ impl SpanStyle {
pub enum SpanSegment {
Start(SpanStyle),
Middle(SpanStyle),
Mark(SpanStyle),
End(SpanStyle),
}
@ -44,6 +45,7 @@ impl SpanSegment {
match self {
Self::Start(s) => *s,
Self::Middle(s) => *s,
Self::Mark(s) => *s,
Self::End(s) => *s,
}
}
@ -195,6 +197,7 @@ impl LineLayout {
DayEntry::ReminderWhile(i, d) => {
let plural = if *d == 1 { "" } else { "s" };
let extra = format!("{d} day{plural} left");
self.mark_span(*i);
self.line_entry(entries, *i, today, Times::Untimed, Some(extra));
}
DayEntry::Undated(i) => {
@ -246,6 +249,15 @@ impl LineLayout {
self.spans.push(Some((index, SpanSegment::Start(style))));
}
fn mark_span(&mut self, index: usize) {
for span in self.spans.iter_mut() {
match span {
Some((i, s)) if *i == index => *s = SpanSegment::Mark(s.style()),
_ => {}
}
}
}
fn stop_span(&mut self, index: usize) {
for span in self.spans.iter_mut() {
match span {
@ -258,7 +270,9 @@ impl LineLayout {
fn step_spans(&mut self) {
for span in self.spans.iter_mut() {
match span {
Some((_, s @ SpanSegment::Start(_))) => *s = SpanSegment::Middle(s.style()),
Some((_, s @ (SpanSegment::Start(_) | SpanSegment::Mark(_)))) => {
*s = SpanSegment::Middle(s.style())
}
Some((_, SpanSegment::End(_))) => *span = None,
_ => {}
}

View file

@ -141,6 +141,7 @@ impl ShowLines {
SpanSegment::Middle(SpanStyle::Solid) => "".bright_black(),
SpanSegment::Middle(SpanStyle::Dashed) => "".bright_black(),
SpanSegment::Middle(SpanStyle::Dotted) => "".bright_black(),
SpanSegment::Mark(_) => "".bright_black(),
SpanSegment::End(_) => "".bright_black(),
};
result.push_str(&format!("{colored_str}"));